#ifndef _DEBUG #define _DEBUG #include __FILE__ int main() { long K; cin >> K; string S{"12345678"}; long ans = 0; do { auto N = stol(S); if (N % K == 0) ans++; } while (next_permutation(S.begin(), S.end())); cout << ans << '\n'; } #else // #undef _DEBUG #include using namespace std; template bool cmin(T& a, const T2& b) { return a > b ? a = b, true : false; } template bool cmax(T& a, const T2& b) { return a < b ? a = b, true : false; } __attribute__((constructor)) void ios_setup() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } template ostream& operator<<(ostream& os, const vector& vec); template ostream& operator<<(ostream& os, const vector >& vec); template ostream& operator<<(ostream& os, const vector > >& vec); template ostream& operator<<(ostream& os, const pair& p) { return os << "(" << p.first << ", " << p.second << ")"; } template ostream& operator<<(ostream& os, const tuple& t) { const auto& [a, b, c] = t; return os << "(" << a << ", " << b << ", " << c << ")"; } template ostream& operator<<(ostream& os, const tuple& t) { const auto& [a, b, c, d] = t; return os << "(" << a << ", " << b << ", " << c << ", " << d << ")"; } template ostream& operator<<(ostream& os, priority_queue pq) { os << "{"; while (!pq.empty()) os << pq.top() << (pq.size() > 1 ? " " : ""), pq.pop(); return os << "}"; } #define FOREACH(it, a) for (auto it = (a).begin(); it != (a).end(); it++) template ostream& operator<<(ostream& os, const set& se) { os << "{"; FOREACH (it, se) { os << (it == se.begin() ? "" : " ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, const multiset& ms) { os << "{"; FOREACH (it, ms) { os << (it == ms.begin() ? "" : " ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, const map& ma) { os << "{"; FOREACH (it, ma) { os << (it == ma.begin() ? "" : " ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, const vector& vec) { os << "{"; FOREACH (it, vec) { os << (it == vec.begin() ? "" : " ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, const vector >& vec) { os << "{\n"; FOREACH (it, vec) { os << (it == vec.begin() ? " " : "\n ") << *it; } return os << "\n}"; } template ostream& operator<<(ostream& os, const vector > >& vec) { os << "{\n"; FOREACH (it, vec) { os << (it == vec.begin() ? "" : "\n") << "(" << it - vec.begin() << ") " << *it; } return os << "\n}"; } void dump() {} template void dump(const Head& head, const Tail&... tail) { cout << head << (sizeof...(tail) ? ", " : "\n"), dump(tail...); } #ifdef _DEBUG #define DUMP(...) cout << "[" << (#__VA_ARGS__) << "] ", dump(__VA_ARGS__) #else #define DUMP(...) (void)0 #endif #endif