#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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1144 KB |
Output is correct |
2 |
Correct |
20 ms |
1144 KB |
Output is correct |
3 |
Correct |
21 ms |
1144 KB |
Output is correct |
4 |
Correct |
21 ms |
1144 KB |
Output is correct |
5 |
Correct |
21 ms |
1116 KB |
Output is correct |
6 |
Correct |
21 ms |
1144 KB |
Output is correct |
7 |
Correct |
21 ms |
1144 KB |
Output is correct |
8 |
Correct |
20 ms |
1144 KB |
Output is correct |
9 |
Correct |
21 ms |
1144 KB |
Output is correct |
10 |
Correct |
21 ms |
1140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1144 KB |
Output is correct |
2 |
Correct |
20 ms |
1144 KB |
Output is correct |
3 |
Correct |
21 ms |
1144 KB |
Output is correct |
4 |
Correct |
21 ms |
1144 KB |
Output is correct |
5 |
Correct |
21 ms |
1116 KB |
Output is correct |
6 |
Correct |
21 ms |
1144 KB |
Output is correct |
7 |
Correct |
21 ms |
1144 KB |
Output is correct |
8 |
Correct |
20 ms |
1144 KB |
Output is correct |
9 |
Correct |
21 ms |
1144 KB |
Output is correct |
10 |
Correct |
21 ms |
1140 KB |
Output is correct |
11 |
Correct |
20 ms |
1144 KB |
Output is correct |
12 |
Correct |
20 ms |
1144 KB |
Output is correct |
13 |
Correct |
21 ms |
1116 KB |
Output is correct |
14 |
Correct |
20 ms |
1144 KB |
Output is correct |
15 |
Correct |
21 ms |
1144 KB |
Output is correct |
16 |
Correct |
21 ms |
1140 KB |
Output is correct |
17 |
Correct |
21 ms |
1144 KB |
Output is correct |
18 |
Correct |
20 ms |
1144 KB |
Output is correct |
19 |
Correct |
21 ms |
1144 KB |
Output is correct |
20 |
Correct |
20 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1144 KB |
Output is correct |
2 |
Correct |
20 ms |
1144 KB |
Output is correct |
3 |
Correct |
21 ms |
1144 KB |
Output is correct |
4 |
Correct |
21 ms |
1144 KB |
Output is correct |
5 |
Correct |
21 ms |
1116 KB |
Output is correct |
6 |
Correct |
21 ms |
1144 KB |
Output is correct |
7 |
Correct |
21 ms |
1144 KB |
Output is correct |
8 |
Correct |
20 ms |
1144 KB |
Output is correct |
9 |
Correct |
21 ms |
1144 KB |
Output is correct |
10 |
Correct |
21 ms |
1140 KB |
Output is correct |
11 |
Correct |
20 ms |
1144 KB |
Output is correct |
12 |
Correct |
20 ms |
1144 KB |
Output is correct |
13 |
Correct |
21 ms |
1116 KB |
Output is correct |
14 |
Correct |
20 ms |
1144 KB |
Output is correct |
15 |
Correct |
21 ms |
1144 KB |
Output is correct |
16 |
Correct |
21 ms |
1140 KB |
Output is correct |
17 |
Correct |
21 ms |
1144 KB |
Output is correct |
18 |
Correct |
20 ms |
1144 KB |
Output is correct |
19 |
Correct |
21 ms |
1144 KB |
Output is correct |
20 |
Correct |
20 ms |
1144 KB |
Output is correct |
21 |
Correct |
21 ms |
1060 KB |
Output is correct |
22 |
Correct |
20 ms |
1144 KB |
Output is correct |
23 |
Correct |
20 ms |
1144 KB |
Output is correct |
24 |
Correct |
21 ms |
1116 KB |
Output is correct |
25 |
Correct |
20 ms |
1144 KB |
Output is correct |
26 |
Correct |
20 ms |
1144 KB |
Output is correct |
27 |
Correct |
21 ms |
1060 KB |
Output is correct |
28 |
Correct |
21 ms |
1144 KB |
Output is correct |
29 |
Correct |
21 ms |
1144 KB |
Output is correct |
30 |
Correct |
21 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1144 KB |
Output is correct |
2 |
Correct |
20 ms |
1144 KB |
Output is correct |
3 |
Correct |
21 ms |
1144 KB |
Output is correct |
4 |
Correct |
21 ms |
1144 KB |
Output is correct |
5 |
Correct |
21 ms |
1116 KB |
Output is correct |
6 |
Correct |
21 ms |
1144 KB |
Output is correct |
7 |
Correct |
21 ms |
1144 KB |
Output is correct |
8 |
Correct |
20 ms |
1144 KB |
Output is correct |
9 |
Correct |
21 ms |
1144 KB |
Output is correct |
10 |
Correct |
21 ms |
1140 KB |
Output is correct |
11 |
Correct |
20 ms |
1144 KB |
Output is correct |
12 |
Correct |
20 ms |
1144 KB |
Output is correct |
13 |
Correct |
21 ms |
1116 KB |
Output is correct |
14 |
Correct |
20 ms |
1144 KB |
Output is correct |
15 |
Correct |
21 ms |
1144 KB |
Output is correct |
16 |
Correct |
21 ms |
1140 KB |
Output is correct |
17 |
Correct |
21 ms |
1144 KB |
Output is correct |
18 |
Correct |
20 ms |
1144 KB |
Output is correct |
19 |
Correct |
21 ms |
1144 KB |
Output is correct |
20 |
Correct |
20 ms |
1144 KB |
Output is correct |
21 |
Correct |
21 ms |
1060 KB |
Output is correct |
22 |
Correct |
20 ms |
1144 KB |
Output is correct |
23 |
Correct |
20 ms |
1144 KB |
Output is correct |
24 |
Correct |
21 ms |
1116 KB |
Output is correct |
25 |
Correct |
20 ms |
1144 KB |
Output is correct |
26 |
Correct |
20 ms |
1144 KB |
Output is correct |
27 |
Correct |
21 ms |
1060 KB |
Output is correct |
28 |
Correct |
21 ms |
1144 KB |
Output is correct |
29 |
Correct |
21 ms |
1144 KB |
Output is correct |
30 |
Correct |
21 ms |
1144 KB |
Output is correct |
31 |
Correct |
20 ms |
1144 KB |
Output is correct |
32 |
Correct |
21 ms |
1144 KB |
Output is correct |
33 |
Correct |
21 ms |
1144 KB |
Output is correct |
34 |
Correct |
22 ms |
1144 KB |
Output is correct |
35 |
Correct |
29 ms |
1144 KB |
Output is correct |
36 |
Correct |
29 ms |
1144 KB |
Output is correct |
37 |
Correct |
30 ms |
1144 KB |
Output is correct |
38 |
Correct |
22 ms |
1144 KB |
Output is correct |
39 |
Correct |
24 ms |
1144 KB |
Output is correct |
40 |
Correct |
25 ms |
1144 KB |
Output is correct |