#include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; //yukicoder 1644 Eight Digit //next_permutation の使い方 int main() { int k, cnt = 0; vector a(8); cin >> k; for(int i = 0; i < 8; i++) a[i] = i+1; do{ int t = 0; for (int i = 0; i < 8; i++){ t += a[i]; if (i != 7) t *= 10; } if (!(t%k)) cnt++; }while (next_permutation(a.begin(), a.end())); cout << cnt << endl; }