#include "bits/stdc++.h" #define int long long using namespace std; using ll = long long; using P = pair; const ll INF = (1LL << 61); ll mod = 1000000007; signed main() { ios::sync_with_stdio(false); cin.tie(0); int K; cin >> K; vectora = { 1, 2, 3, 4,5, 6, 7, 8 }; int ans = 0; do { vectorb = a; reverse(b.begin(), b.end()); int now = 0; int t = 1; for (int i = 0; i < 8; i++) { now += b[i] * t; t *= 10; } if (now % K == 0)ans++; } while (next_permutation(a.begin(), a.end())); cout << ans << endl; return 0; }