#define _GLIBCXX_DEBUG #include "bits/stdc++.h" //#include //AtCoder (gcc) 上ではこれがあると動かない。__popcnt用のincludeファイル。 using namespace std; using Graph = vector>; typedef long long ll; typedef long double ld; #define int long long #define rep(i, n) for(long long i = 0; i < (n); i++) #define sqrt(d) pow((long double) (d), 0.50) const int INF = 2e9; const ll large_P = 1e9 + 7; //繰り返し2乗法 //N^aの、Mで割った余りを求める。 ll my_pow(ll N, ll a, ll M) { ll tempo; if (a == 0) { return 1; } else { if (a % 2 == 0) { tempo = my_pow(N, a / 2, M); return (tempo * tempo) % M; } else { tempo = my_pow(N, a - 1, M); return (tempo * N) % M; } } } //N_C_a を M で割った余り ll my_combination(ll N, ll a, ll M) { ll answer = 1; rep(i, a) { answer *= (N - i); answer %= M; } rep(i, a) { answer *= my_pow(i + 1, M - 2, M); answer %= M; } return answer; } signed main() { int N, M; cin >> N >> M; ll res = 0LL; vector combination(M + 1, 0); //i番目に M_C_i for (int i = M; i >= 1; i--) { if (i == M) { combination.at(M - i) = 1; } else { combination.at(M - i) = combination.at(M - i - 1) * (i + 1); combination.at(M - i) %= large_P; combination.at(M - i) *= my_pow(M - i, large_P - 2, large_P); combination.at(M - i) %= large_P; } ll temp = (my_pow(i, N, large_P) * combination.at(M - i)) % large_P; if ((M - i) % 2 == 0) { res += temp; res %= large_P; //cout << res << endl; } else { res -= temp; res %= large_P; //cout << res << endl; } } cout << res << endl; rep(i, M+1) { //cout << i << ": " << combination.at(i) << endl;; } }