#include using namespace std; using ll=long long; using ull=unsigned long long; const ll MOD=1000000000+7; #define rep(I,N) for(int I=0;I; using vvec = vector>; ll lcm(ll a,ll b){ return a/__gcd(a,b)*b; } int main(){ int k; cin >> k; string s="12345678"; int count=0; while(1){ if(stoi(s)%k==0)count++; if(!next_permutation(ALL(s)))break; } printf("%d\n",count); }