#include #include using namespace std; int main(){ string s = "12345678"; int k;cin>>k; int ans = 0; do{ if(stoi(s)%k == 0)ans++; }while(next_permutation(s.begin(),s.end())); cout << ans << endl; }