This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9 + 7, maxn = 1e5 + 5;
int fact[maxn], ifact[maxn];
int N, K;
int power(int a, int b) {
if (b == 0) return 1;
int res = power(a, b / 2);
if (b & 1) return (ll)res * res % mod * a % mod;
return (ll)res * res % mod;
}
int inv(int a) {
return power(a, mod - 2);
}
int binom(int k, int n) {
if (k < 0 || n < 0 || k > n) return 0;
return (ll)fact[n] * ifact[k] % mod * ifact[n - k] % mod;
}
void add(int & x, int y) {
x += y;
if (x >= mod) x -= mod;
if (x < 0) x += mod;
}
signed main(void) {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
#endif // LOCAL
fact[0] = 1;
for (int i = 1; i < maxn; ++i) {
fact[i] = (ll)fact[i - 1] * i % mod;
}
ifact[maxn - 1] = inv(fact[maxn - 1]);
for (int i = maxn - 2; i >= 0; --i) {
ifact[i] = (ll)ifact[i + 1] * (i + 1) % mod;
}
cin >> N >> K;
int res = 0;
for (int i = 0; i <= K; ++i) {
int sign = 1;
if (i & 1) sign = -1;
int way = (ll)power(K - i, N) * binom(i, N + 1) % mod;
///cerr << way << '\n';
add(res, sign * way);
}
cout << res;
}
# | 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... |