/*{{{ author: ryota2357 */ #include #include #include #include #include #include #include #include #include #include #include #include #include namespace ryota2357 { template inline std::istream& operator>>(std::istream& is, std::pair& P) noexcept { return is >> P.first >> P.second; } template inline std::istream& operator>>(std::istream& is, std::vector& V) noexcept { for (auto& v : V) is >> v; return is; } template inline std::ostream& operator<<(std::ostream& os, const std::vector& V) noexcept { const auto n = V.size() - 1; for (int i = 0; i < n; ++i) os << V[i] << ' '; return os << V.back(); } inline void IN(void) noexcept { return; } template inline void IN(T& t, U&... u) noexcept { std::cin >> t; IN(u...); } template inline void OUT(const T& x) noexcept { std::cout << x << '\n'; } template inline bool chmax(T& a, const T& b) noexcept { return a < b ? a = b, true : false; } template inline bool chmin(T& a, const T& b) noexcept { return a > b ? a = b, true : false; } template inline T read(void) { T ret = 0; char c = getchar(); while ((c < '0' || '9' < c) && c != '-') c = getchar(); const bool f = (c == '-') && (c = getchar()); while ('0' <= c && c <= '9') { ret = 10 * ret + c - '0'; c = getchar(); } return f ? -ret : ret; } template inline T ceil_div(const T& a, const T& b) { assert(b != 0); return (a + (b - 1)) / b; } template inline T max(const std::vector& v) { return *max_element(v.begin(), v.end()); } template inline T min(const std::vector& v) { return *min_element(v.begin(), v.end()); } } // namespace ryota2357 using ll = long long; using pint = std::pair; #define rep(i, a, b) for (ll i = (a); i < ll(b); ++i) #define repr(i, a, b) for (ll i = (a); i >= ll(b); --i) #define each(x, v) for (auto& x : v) #define All(x) (x).begin(), (x).end() #define AllR(x) (x).rbegin(), (x).rend() #define Sort(x) (sort((x).begin(), (x).end())) #define SortR(x) (sort((x).rbegin(), (x).rend())) #define Unique(x) (x.erase(unique((x).begin(), (x).end()), (x).end())) #define Fill(v, n) (fill((v), (v) + sizeof(v) / sizeof(*(v)), (v))) #define INF (1073741823) #define INFL (2305843009213693951ll) using namespace std; using namespace ryota2357; /*}}}*/ template struct ModInt { ll value; constexpr ModInt(const ll value = 0) noexcept : value((value % Modulus + Modulus) % Modulus) {} inline ModInt& operator+=(const ModInt& rhs) noexcept { if (value += rhs.value, value >= Modulus) value -= Modulus; return *this; } inline ModInt& operator-=(const ModInt& rhs) noexcept { if (value -= rhs.value, value < 0) value += Modulus; return *this; } inline ModInt& operator*=(const ModInt& rhs) noexcept { value = value * rhs.value % Modulus; return *this; } inline ModInt& operator/=(const ModInt& rhs) noexcept { value = value * inv(rhs.value).value % Modulus; return *this; } inline ModInt& operator++() noexcept { if (++value >= Modulus) value -= Modulus; return *this; } inline ModInt operator++(int) noexcept { ModInt t = value; if (++value >= Modulus) value -= Modulus; return t; } inline ModInt& operator--() noexcept { if (--value < 0) value += Modulus; return *this; } inline ModInt operator--(int) noexcept { ModInt t = value; if (--value < 0) value += Modulus; return t; } inline ModInt operator-() const noexcept { return (-value + Modulus) % Modulus; } inline ModInt inv(void) const { return inv(value); } ModInt inv(const ll& n) const { ll a = n, b = Modulus, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if (u %= Modulus, u < 0) u += Modulus; return u; } ModInt pow(ll n) const { assert(0 <= n); if (!n) return 1; ModInt t = pow(n >> 1); t *= t; if (n & 1) t *= (*this); return t; } friend inline ModInt operator+(const ModInt& lhs, const ModInt& rhs) noexcept { return ModInt(lhs) += rhs; } friend inline ModInt operator-(const ModInt& lhs, const ModInt& rhs) noexcept { return ModInt(lhs) -= rhs; } friend inline ModInt operator*(const ModInt& lhs, const ModInt& rhs) noexcept { return ModInt(lhs) *= rhs; } friend inline ModInt operator/(const ModInt& lhs, const ModInt& rhs) noexcept { return ModInt(lhs) /= rhs; } friend inline bool operator==(const ModInt& lhs, const ModInt& rhs) noexcept { return lhs.value == rhs.value; } friend inline bool operator!=(const ModInt& lhs, const ModInt& rhs) noexcept { return lhs.value != rhs.value; } friend inline istream& operator>>(istream& is, ModInt& x) noexcept { ll val; is >> val; x = val; return is; } friend inline ostream& operator<<(ostream& os, const ModInt& x) noexcept { return os << x.value; } }; using mint = ModInt; int main() { ll n, p; IN(n, p); mint nnn = 1; mint cnt = 0; rep(i, 1, n + 1) { nnn *= i; if (i % p == 0) { cnt += 1; } } nnn = nnn.pow(nnn.value); OUT(cnt * nnn); return 0; }