#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i, N) for (int i = 0; i < (int)N; i++) #define FOR(i, a, b) for (int i = a; i < (int)b; i++) #define ALL(x) (x).begin(), (x).end() using namespace std; constexpr int inf = 1 << 30; constexpr long long llinf = 1LL << 62; constexpr int mod = 1000000007; using ll = long long; template struct Math { vector fact, factinv, inv; Math(int n = 100000) { fact.resize(n + 1); factinv.resize(n + 1); inv.resize(n + 1); fact[0] = fact[1] = 1; factinv[0] = factinv[1] = 1; inv[1] = 1; for (int i = 2; i <= n; ++i) { fact[i] = fact[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; factinv[i] = factinv[i - 1] * inv[i] % MOD; } } long long C(int n, int r) { if (n < r || n < 0 || r < 0) { return 0; } else { return fact[n] * (factinv[r] * factinv[n - r] % MOD) % MOD; } } long long P(int n, int r) { if (n < r || n < 0 || r < 0) { return 0; } else { return fact[n] * factinv[n - r] % MOD; } } long long H(int n, int r) { return C(n + r - 1, r); } }; namespace phc { long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a) { long long b = mod, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } } // namespace phc template struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt& operator+=(const ModInt& p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt& operator-=(const ModInt& p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt& operator*=(const ModInt& p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt& operator/=(const ModInt& p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt& p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt& p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt& p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt& p) const { return ModInt(*this) /= p; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream& operator<<(ostream& os, const ModInt& p) { return os << p.x; } friend istream& operator>>(istream& is, ModInt& a) { int64_t t; is >> t; a = ModInt(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt; int main() { ll N, P; cin >> N >> P; modint ans = 0; for (ll x = 1; x <= N; ++x) { ll y = x; while (y % P == 0) { ans += 1; y /= P; } } Math m1(N); Math m2(N); cout << (ans * phc::modpow(m1.fact[N], m2.fact[N])).x << endl; return 0; }