MOD = 10 ** 9 + 7 n, p = map(int, input().split()) power = 1 base = 1 for x in range(2, n + 1): power = (power * x) % (MOD - 1) base = (base * x) % MOD dp = [0 for _ in range(n + 1)] for x in range(2, n + 1): cur = x while cur % p == 0: dp[x] += 1 cur //= p ans = sum(dp) % MOD * pow(base, power, MOD) % MOD print(ans)