#include using namespace std; using ll = long long; int main() { vector v; string out; int cnt,num; cin >> num; cnt = 0; v = {"1","2","3","4","5","6","7","8"}; do{ out = ""; for(int i=0;i<8;i++){ out += v[i]; } if((stoi(out)%num)==0){ cnt += 1; } }while (next_permutation(v.begin(),v.end())); cout << cnt << endl; }