#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int k; cin >> k; int i=0; int counter=0; vector jun(40320); vector v={1,2,3,4,5,6,7,8}; sort(v.begin(),v.end()); do{ int t=0; for(int j=0; j<8;j++){ t+=v[j]*pow(10,j); } jun[i]=t; i++; }while (next_permutation(v.begin(), v.end())); for(int j=0; j<40320;j++){ if(jun[j]%k==0) counter++; } cout << counter << endl; }