#include using namespace std; int k, m = 0; vector v = { 1, 2, 3, 4, 5, 6, 7, 8 }; int main() { cin >> k; do { int t = 0; for (vector::iterator itr = v.begin(); itr != v.end(); itr++) { t *= 10; t += *itr; } if (t % k == 0) m++; } while (next_permutation(v.begin(), v.end())); cout << m << endl; }