#include // #include // #include using namespace std; // using namespace atcoder; #define SZ(x) (int)(x).size() #define dout(x) printf("%.10f\n", (double)(x)) #define ALL(s) (s).begin(), (s).end() #define so(V) sort(ALL(V)) #define rev(V) reverse(ALL(V)) typedef pair P; typedef pair Pl; typedef vector> vvi; typedef vector> vvl; long gcd(long a, long b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } /* lcm (a, b) : 2整数版 入力:整数 a, b 出力:aとbの最小公倍数 */ long lcm(long a, long b) { long d = gcd(a, b); return a / d * b; } int main() { long N, P, waru = 1000000007; cin >> N >> P; long ans = 1, zn = 0, sinans = 1, tasu; for (long i = N; i > 0; i--) { sinans *= i; sinans %= waru; ans = i; while (ans % P == 0) { ans /= P; zn++; zn %= waru; } } ans = 1; tasu = sinans; for (long i = 0; ((long)1 << i) <= sinans; i++) { if (((long)1 << i) & sinans) { ans *= tasu; ans %= waru; } tasu *= tasu; tasu %= waru; } long fans = zn * ans; fans %= waru; cout << fans << endl; return 0; }