#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int k; cin >> k; vector p(8); iota(p.begin(), p.end(), 1); int ans = 0; do { int num = 0; for (int i = 0; i < 8; i++) { num = num * 10 + p[i]; } if (num % k == 0) { ans++; } } while (next_permutation(p.begin(), p.end())); cout << ans << endl; }