#define _GLIBCXX_DEBUG #include using namespace std; int main() { int K, ans = 0; cin >> K; string S = "12345678"; for(int i = 0; i < 40320; i++){ int s = stoi(S); if(s%K == 0) ans++; next_permutation(S.begin(), S.end()); } cout << ans << endl; }