#include #include using namespace std; const int MOD = 1e9 + 7; const int MAX = 1e5 + 10; long long fact[MAX]; // 阶乘数组 long long inv_fact[MAX]; // 阶乘的逆元数组 // 快速幂计算 (a^b) mod MOD long long powmod(long long a, long long b) { long long res = 1; a %= MOD; while (b > 0) { if (b % 2 == 1) { res = res * a % MOD; } a = a * a % MOD; b /= 2; } return res; } // 预处理阶乘和逆元阶乘 void precompute() { fact[0] = 1; for (int i = 1; i < MAX; ++i) { fact[i] = fact[i-1] * i % MOD; } // 费马小定理求逆元:inv_fact[MAX-1] = fact[MAX-1]^(MOD-2) mod MOD inv_fact[MAX-1] = powmod(fact[MAX-1], MOD-2); for (int i = MAX-2; i >= 0; --i) { inv_fact[i] = inv_fact[i+1] * (i+1LL) % MOD; } } // 计算组合数 C(m, k) = m!/(k!*(m-k)!) mod MOD long long comb(int m, int k) { if (k < 0 || k > m) return 0; return fact[m] * inv_fact[k] % MOD * inv_fact[m - k] % MOD; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); precompute(); int N, M; cin >> N >> M; long long ans = 0; for (int k = 0; k <= M; ++k) { long long c = comb(M, k); // 符号项:(-1)^k 等价于 MOD-1 当k为奇数,1当k为偶数 long long sign = (k % 2 == 0) ? 1 : MOD - 1; long long p = powmod(M - k, N); long long term = sign * c % MOD; term = term * p % MOD; ans = (ans + term) % MOD; } cout << ans << '\n'; return 0; }