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