#include #include #include #include using namespace std; typedef long long ll; vector ans(100005, 1); long long M = 1e9 + 7; map, ll> cmb; 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; ans[1] = m; ans[n] = qpow(m, n); int k = -1; for (int j = 1; j < m; ++j) { ans[n] += k * qpow(j, n) * comp(m, j, M) % M; ans[n] = (ans[n] + M) % M; k *= -1; } cout << ans[n] << endl; return 0; }