p=10**9+7 def exp(a,b,p): ans,mul,div=1,a,1 for i in range(70): if b//div%2==1: ans*=mul ans%=p mul=mul**2%p div*=2 return ans%p N,P=map(int,input().split()) p=10**9+7 Ps=P Nc=N//P while Ps*Ps<=N: Ps=Ps*Ps Nc+=N//Ps #NbはN!をpで割ったあまり Nb=1 for i in range(1,N+1): Nb*=i Nb%=p Nub=1 for i in range(1,N+1): Nub*=i Nub%=(p-1) print(Nc*exp(Nb,Nub,p)%p)