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