/* -*- coding: utf-8 -*- * * 1035.cc: No.1035 Color Box - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int MOD = 1000000007; /* typedef */ typedef long long ll; /* global variables */ int fs[MAX_N + 1], invfs[MAX_N + 1]; /* subroutines */ int powmod(int a, int n) { // a^n % MOD int pm = 1; while (n > 0) { if (n & 1) pm = (ll)pm * a % MOD; a = (ll)a * a % MOD; n >>= 1; } return pm; } inline int nck(int n, int k) { // nCk % MOD return (ll)fs[n] * invfs[n - k] % MOD * invfs[k] % MOD; } void prepare_fracs(int n) { fs[0] = invfs[0] = 1; for (int i = 1; i <= n; i++) { fs[i] = (ll)fs[i - 1] * i % MOD; invfs[i] = powmod(fs[i], MOD - 2); } } /* main */ int main() { int n, m; scanf("%d%d", &n, &m); prepare_fracs(n); int sum = 0; for (int i = 0; i < m; i++) { int d = (ll)powmod(m - i, n) * nck(m, m - i) % MOD; if (i & 1) d = MOD - d; sum = (sum + d) % MOD; } printf("%d\n", sum); return 0; }