#include #include #include #include using namespace std; typedef long long ll; vector ans(100005, 1); long long M = 1e9 + 7; map, ll> cmb; int ff[100005]; int gcd(int a,int b) { if(b==0) return a; else return gcd(b,a%b); } int x,y; void Extended_gcd(int a,int b) { if(b==0) { x=1; y=0; } else { Extended_gcd(b,a%b); long t=x; x=y; y=t-(a/b)*y; } } int C(int a,int b) { if(b>a) return 0; b=(ff[a-b]*ff[b])%M; a=ff[a]; int c=gcd(a,b); a/=c; b/=c; Extended_gcd(b,M); x=(x+M)%M; x=(x*a)%M; return x; } int Combination(int n, int m) { int ans=1; int a,b; while(m||n) { a=n%M; b=m%M; n/=M; m/=M; ans=(ans*C(a,b))%M; } return ans; } long long qpow(long long a, long long n) { long long ret = 1; a = (a % M + M) % M; for (; n; n >>= 1) { if (n & 1) ret = (ret * a) % M; a = (a * a) % M; } return ret; } ll comp(ll a,ll b,ll p)//composite num C(a,b)%p { if (cmb.count(make_pair(a,b))) return cmb[make_pair(a, b)]; if (cmb.count(make_pair(a,a-b))) return cmb[make_pair(a, a-b)]; if(aa-b)b=a-b; int ans=1,ca=1,cb=1; for(ll i=0;i> n >> m; ff[0]=1; for(int i=1;i<=100004;i++) ff[i]=(ff[i-1]*i)%M; ans[1] = m; ans[n] = qpow(m, n); int k = -1; for (int j = 1; j < m; ++j) { ans[n] += k * qpow(j, n) * Combination(m, j ) % M; ans[n] = (ans[n] + M) % M; k *= -1; } cout << ans[n] << endl; return 0; }