#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; int K, ans = 0; ll N; string S; int main() { cin >> K; S = "12345678"; do { N = stoll(S); if (N % K == 0) ans++; } while (next_permutation(S.begin(), S.end())); cout << ans << endl; return 0; }