简单的容斥
∑i=0m(−1)i(m−i)n(mi)
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1000005,MOD=1e9+7;
typedef long long LL;
int n,m,a[maxn],ans;
LL fac[maxn],inv[maxn],fac_inv[maxn];
LL C(int n,int m){ return fac[n]*fac_inv[m]%MOD*fac_inv[n-m]%MOD; }
LL Pow(LL a,int b){
LL res=1;
for(;b;b>>=1,a=a*a%MOD) if(b&1) res=(res*a)%MOD;
return res;
}
int main(){
//freopen("A.in","r",stdin);
//freopen("A.out","w",stdout);
fac[0]=1; for(int i=1;i<=1000000;i++) fac[i]=fac[i-1]*i%MOD;
inv[1]=1; for(int i=2;i<=1000000;i++) inv[i]=(LL)(MOD-MOD/i)*inv[MOD%i]%MOD;
fac_inv[0]=1; for(int i=1;i<=1000000;i++) fac_inv[i]=fac_inv[i-1]*inv[i]%MOD;
scanf("%d%d",&n,&m);
for(int i=0;i<=m;i++)
(ans+=Pow(m-i,n)*C(m,i)*(i&1?-1:1)%MOD)%=MOD;
printf("%d\n",(ans+MOD)%MOD);
return 0;
}