#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; bool printb(bool f) { if (f)printf("Yes\n"); else printf("No\n"); return f; } template void prt(T t, string sep = "\n") { cout << t << sep; return; } template void printl(vector a, string sep = " ") { for (int i = 0; i < a.size(); i++) { cout << a[i] << sep; } cout << "\n"; return; } #define all(a) a.begin(),a.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) using llong = long long; using pii = pair; using pll = pair; using pli = pair; using pil = pair; template using vec2 = vector>; template inline bool chmin(T& a, T b) { return (a > b) ? (a = b, true) : false; } template inline bool chmax(T& a, T b) { return (a < b) ? (a = b, true) : false; } bool bitIn(llong a, int b) { return ((a >> b) & 1); } int bitCnt(llong a) { int re = 0; while (a > 0) { if (a & 1)re++; a >>= 1; } return re; } llong powL(llong n, llong i) { llong re = 1; while (i >= 1) { if (i & 1) re *= n; n *= n; i >>= 1; } return re; } llong powL_M(llong n, llong i, llong m) { llong re = 1; while (i >= 1) { if (i & 1) { re *= n; re %= m; } n *= n; n %= m; i >>= 1; } return re; } struct point { llong x = 0, y = 0; }; //lからrまでの和を返す template T sum_num(T l, T r) { if (((l + r) & 1) == 0) { return (l + r) / 2 * (l - r + 1); } else { return (l - r + 1) / 2 * (l + r); } } int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 }; struct edge { int to, co; }; static const double pi = 3.14159265358979; /* modintクラス。四則演算と累乗が定義されている。 割り算はmodが素数でない時にも使える。(逆元の存在条件注意) extGCD(),GCD()を含む */ /* template T extGCD(T a, T b, T& x, T& y) { if (b == 0) { x = 1; y = 0; return a; } T gcd = extGCD(b, a % b, y, x); y -= a / b * x; return gcd; } template T GCD(T a, T b) { T x, y; return extGCD(a, b, x, y); } static const int mod = 1e9 + 7; //問題文に合わせて変更すること class modint { public: long long x; modint(long long x = 0) :x((x% mod + mod) % mod) {} modint operator-() const { return (-x); } modint& operator+=(const modint& a) { if ((x += a.x) >= mod)x -= mod; return *this; } modint& operator-=(const modint& a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } modint& operator*=(const modint& a) { (x *= a.x) %= mod; return *this; } modint operator+(const modint& a) const { modint res(*this); return res += a; } modint operator-(const modint& a) const { modint res(*this); return res -= a; } modint operator*(const modint& a) const { modint res(*this); return res *= a; } modint inv() const { long long y, c; extGCD(x, (long long)mod, y, c); return y; } modint& operator/=(const modint& a) { return (*this) *= a.inv(); } modint operator/ (const modint& a) const { modint res(*this); return res /= a; } friend ostream& operator<<(ostream& os, const modint& a) { os << a.x; return os; } }; //pow(a , n) modint型aのn乗のmodを求める template modint powM(modint a, T n) { modint re(1); while (n > 0) { if (n & 1)re *= a; a *= a; n >>= 1; } return re; } //*/ int main() { int n, p; cin >> n >> p; int m2 = 1e9 + 7; llong si2 = 1; llong si1 = 1; int m1 = 1e9 + 6; rep(i, n) { si2 *= (i + 1); si2 %= m2; si1 *= (i + 1); si1 %= m1; } llong y = powL_M(si2, si1, 1e9 + 7); int num = 0; //pがn!に何回掛けられてるか rep(i, n) { int k = i + 1; while (k % p == 0) { k /= p; num++; } } prt(num* y% int(1e9 + 7)); }