#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define ll long long
#define fi first
#define se second
#define ii pair<ll, ll>
const int mxN = 1e5 + 7, MOD = 1e9 + 7;
int n, k;
ll gt[mxN], rev[mxN];
int pw(int j, int mx)
{
if (!mx)
return 1;
ll res = pw(j, mx / 2);
res = res * res % MOD;
if (mx % 2)
return res * j % MOD;
return res;
}
ll C(int u, int v)
{
return gt[v] * rev[u] % MOD * rev[v - u] % MOD;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
cin >> n >> k;
gt[0] = rev[0] = 1;
for (int i = 1; i <= n + 1; i++)
{
gt[i] = gt[i - 1] * i % MOD;
rev[i] = pw(gt[i], MOD - 2);
}
ll ans = 0;
for (int i = 0; i <= k; i++)
{
if (i % 2)
ans = (ans - C(i, n + 1) * pw(k - i, n) % MOD + MOD) % MOD;
else
ans = (ans + C(i, n + 1) * pw(k - i, n)) % MOD;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |