#include #include #include #include #include #include #include #include #include #include #include #include #define all(v) (v).begin(), (v).end() #define rep(i, j) for (ll i = 0; i < j; ++i) #define rep2(i, j, k) for (ll i = j; i <= k; ++i) #define rep3(i, j, k) for (ll i = j; i >= k; --i) using namespace std; using ld = long double; using ll = long long; using pi = pair; using pl = pair; using vi = vector; using vl = vector; using vpi = vector; using vpl = vector; using vvi = vector; using vvl = vector; using vvpi = vector; using vvpl = vector; template using pqg = priority_queue, greater>; template inline bool chmax(S& x, T y) { if (x < y) { x = y; return 1; } return 0; } template inline bool chmin(S& x, T y) { if (x > y) { x = y; return 1; } return 0; } constexpr int INF = 1000000000; constexpr int MAX = 5005; constexpr int MOD = 1000000007; constexpr ll INFLL = 1000000000000000000; int main(void) { string s = "12345678"; ll k, ans = 0; cin >> k; do { ll val = stoll(s); if (val % k == 0) ++ans; } while (next_permutation(all(s))); cout << ans << endl; return (0); }