def func(x,p): res = 0 y = p while x//y != 0: res += x//y y*=p return res MOD = 10**9+7 N,P = map(int,input().split()) tmp = 1 for i in range(2,N+1): tmp = (tmp*i)%MOD print(func(N,P)*pow(tmp,tmp,MOD)%MOD)