using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, p) = (c[0], c[1]); var mod = 1_000_000_007; var f1 = new int[n + 1]; f1[1] = 1; for (var i = 2; i < f1.Length; ++i) f1[i] = f1[i - 1] * i % mod; var f2 = new int[n + 1]; f2[1] = 1; for (var i = 2; i < f2.Length; ++i) f2[i] = f2[i - 1] * i % (mod - 1); var cnt = Exp(f1[n], f2[n], mod); var mul = 0; for (var i = 1; i <= n; ++i) { var tmp = i; while (tmp % p == 0) { ++mul; tmp /= p; } } WriteLine(cnt * mul % mod); } static long Exp(long n, long k, int mod) { if (k == 0) return 1; if (k == 1) return n % mod; var half = Exp(n, k / 2, mod); var result = (half * half) % mod; return ((k % 2) == 0) ? result : ((result * n) % mod); } }