#include #define rep(i, n) for (int i = 0; i < (n); ++i) using std::cin; using std::cout; using std::vector; int main() { int k; cin >> k; vector a(8); iota(a.begin(), a.end(), 1); int ans = 0; do { int x = 0; rep(i, 8) x = x * 10 + a[i]; if (x % k == 0) ++ans; } while(next_permutation(a.begin(), a.end())); cout << ans << '\n'; return 0; }