n, p = map(int, input().split()) x1, x2, c = 1, 1, 0 MOD = 10**9 + 7 for i in range(n): x1 *= i + 1 x1 %= MOD x2 *= i + 1 x2 %= MOD - 1 y = i + 1 while y % p == 0: c += 1 y //= p print(c * pow(x1, x2, MOD) % MOD)