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>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 7;
const int md = 1e9 + 7;
void add(int &a, int b) {
a += b;
if (a >= md) a -= md;
}
void sub(int &a, int b) {
a -= b;
if (a < 0) a += md;
}
int mul(int a, int b) {
return ((ll)a * b) % md;
}
int power(int a, ll b) {
int res = 1;
while (b > 0) {
if (b & 1) res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
}
int inv(int x) {
return power(x, md - 2);
}
int f[N], rf[N];
int C(int n, int k) {
return mul(f[n], mul(rf[n - k], rf[k]));
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, k;
cin >> n >> k;
--k;
f[0] = 1;
for (int i = 1; i < N; ++i) f[i] = mul(f[i - 1], i);
for (int i = 0; i < N; ++i) rf[i] = inv(f[i]);
int ans = 0;
for (int i = 0; i <= k; ++i) {
int cur = mul(C(n + 1, i), power(k + 1 - i, n));
if (i % 2 == 0) add(ans, cur);
else sub(ans, cur);
}
cout << ans << '\n';
}
# | 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... |