#include #include #include #include #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //cout << fixed << setprecision(15); int k; cin >> k; string s = "12345678"; int ans = 0; do { int s2 = stoi(s); if (s2 % k == 0) ans++; } while (next_permutation(s.begin() , s.end())); cout << ans << endl; return 0; }