#include #include #include using namespace std; typedef long long LL; int main() { vector myVec(8); int i; for (i = 1; i <= 8; i++) { myVec[i-1] = i; } int K; cin >> K; int ans = 0; do { LL num = 0; int N = 10000000; for (i = 0; i < 8; i++) { num += myVec[i] * N; N /= 10; } if (num %K == 0) { ans++; } } while (next_permutation(myVec.begin(), myVec.end())); cout << ans << endl; return 0; }