#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll mod = 1e9 + 7;
ll modpow(ll a, ll b) {
ll ret = 1;
while (b) {
if (b & 1) ret = ret * a % mod;
a = a * a % mod;
b >>= 1;
}
return ret;
}
ll fac[400010];
ll inv[400010];
ll C(ll n, ll r) {
if (n < r) return 0;
return fac[n] * inv[r] % mod * inv[n-r] % mod;
}
int main() {
ios_base :: sync_with_stdio(false); cin.tie(NULL);
fac[0] = 1;
for (ll i=1; i<=400000; i++) {
fac[i] = fac[i-1] * i % mod;
}
inv[400000] = modpow(fac[400000], mod-2);
for (ll i=399999; i>=0; i--) {
inv[i] = inv[i+1] * (i+1) % mod;
}
ll n, k;
cin >> n >> k;
ll ans = modpow(k, n);
for (ll i=1; i<=k-1; i++) {
ll cur = modpow(k-i, n) * C(n+1, i) % mod;
if (i & 1) ans = (ans - cur + mod) % mod;
else ans = (ans + cur) % mod;
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6492 KB |
Output is correct |
2 |
Correct |
7 ms |
6492 KB |
Output is correct |
3 |
Correct |
7 ms |
6492 KB |
Output is correct |
4 |
Correct |
7 ms |
6492 KB |
Output is correct |
5 |
Correct |
7 ms |
6468 KB |
Output is correct |
6 |
Correct |
7 ms |
6492 KB |
Output is correct |
7 |
Correct |
7 ms |
6488 KB |
Output is correct |
8 |
Correct |
7 ms |
6744 KB |
Output is correct |
9 |
Correct |
7 ms |
6720 KB |
Output is correct |
10 |
Correct |
7 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6492 KB |
Output is correct |
2 |
Correct |
7 ms |
6492 KB |
Output is correct |
3 |
Correct |
7 ms |
6492 KB |
Output is correct |
4 |
Correct |
7 ms |
6492 KB |
Output is correct |
5 |
Correct |
7 ms |
6468 KB |
Output is correct |
6 |
Correct |
7 ms |
6492 KB |
Output is correct |
7 |
Correct |
7 ms |
6488 KB |
Output is correct |
8 |
Correct |
7 ms |
6744 KB |
Output is correct |
9 |
Correct |
7 ms |
6720 KB |
Output is correct |
10 |
Correct |
7 ms |
6492 KB |
Output is correct |
11 |
Correct |
7 ms |
6492 KB |
Output is correct |
12 |
Correct |
7 ms |
6500 KB |
Output is correct |
13 |
Correct |
7 ms |
6492 KB |
Output is correct |
14 |
Correct |
7 ms |
6492 KB |
Output is correct |
15 |
Correct |
7 ms |
6492 KB |
Output is correct |
16 |
Correct |
7 ms |
6720 KB |
Output is correct |
17 |
Correct |
7 ms |
6492 KB |
Output is correct |
18 |
Correct |
7 ms |
6492 KB |
Output is correct |
19 |
Correct |
7 ms |
6492 KB |
Output is correct |
20 |
Correct |
8 ms |
6612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6492 KB |
Output is correct |
2 |
Correct |
7 ms |
6492 KB |
Output is correct |
3 |
Correct |
7 ms |
6492 KB |
Output is correct |
4 |
Correct |
7 ms |
6492 KB |
Output is correct |
5 |
Correct |
7 ms |
6468 KB |
Output is correct |
6 |
Correct |
7 ms |
6492 KB |
Output is correct |
7 |
Correct |
7 ms |
6488 KB |
Output is correct |
8 |
Correct |
7 ms |
6744 KB |
Output is correct |
9 |
Correct |
7 ms |
6720 KB |
Output is correct |
10 |
Correct |
7 ms |
6492 KB |
Output is correct |
11 |
Correct |
7 ms |
6492 KB |
Output is correct |
12 |
Correct |
7 ms |
6500 KB |
Output is correct |
13 |
Correct |
7 ms |
6492 KB |
Output is correct |
14 |
Correct |
7 ms |
6492 KB |
Output is correct |
15 |
Correct |
7 ms |
6492 KB |
Output is correct |
16 |
Correct |
7 ms |
6720 KB |
Output is correct |
17 |
Correct |
7 ms |
6492 KB |
Output is correct |
18 |
Correct |
7 ms |
6492 KB |
Output is correct |
19 |
Correct |
7 ms |
6492 KB |
Output is correct |
20 |
Correct |
8 ms |
6612 KB |
Output is correct |
21 |
Correct |
8 ms |
6492 KB |
Output is correct |
22 |
Correct |
7 ms |
6532 KB |
Output is correct |
23 |
Correct |
7 ms |
6652 KB |
Output is correct |
24 |
Correct |
7 ms |
6492 KB |
Output is correct |
25 |
Correct |
7 ms |
6488 KB |
Output is correct |
26 |
Correct |
8 ms |
6492 KB |
Output is correct |
27 |
Correct |
7 ms |
6492 KB |
Output is correct |
28 |
Correct |
7 ms |
6492 KB |
Output is correct |
29 |
Correct |
8 ms |
6492 KB |
Output is correct |
30 |
Correct |
7 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6492 KB |
Output is correct |
2 |
Correct |
7 ms |
6492 KB |
Output is correct |
3 |
Correct |
7 ms |
6492 KB |
Output is correct |
4 |
Correct |
7 ms |
6492 KB |
Output is correct |
5 |
Correct |
7 ms |
6468 KB |
Output is correct |
6 |
Correct |
7 ms |
6492 KB |
Output is correct |
7 |
Correct |
7 ms |
6488 KB |
Output is correct |
8 |
Correct |
7 ms |
6744 KB |
Output is correct |
9 |
Correct |
7 ms |
6720 KB |
Output is correct |
10 |
Correct |
7 ms |
6492 KB |
Output is correct |
11 |
Correct |
7 ms |
6492 KB |
Output is correct |
12 |
Correct |
7 ms |
6500 KB |
Output is correct |
13 |
Correct |
7 ms |
6492 KB |
Output is correct |
14 |
Correct |
7 ms |
6492 KB |
Output is correct |
15 |
Correct |
7 ms |
6492 KB |
Output is correct |
16 |
Correct |
7 ms |
6720 KB |
Output is correct |
17 |
Correct |
7 ms |
6492 KB |
Output is correct |
18 |
Correct |
7 ms |
6492 KB |
Output is correct |
19 |
Correct |
7 ms |
6492 KB |
Output is correct |
20 |
Correct |
8 ms |
6612 KB |
Output is correct |
21 |
Correct |
8 ms |
6492 KB |
Output is correct |
22 |
Correct |
7 ms |
6532 KB |
Output is correct |
23 |
Correct |
7 ms |
6652 KB |
Output is correct |
24 |
Correct |
7 ms |
6492 KB |
Output is correct |
25 |
Correct |
7 ms |
6488 KB |
Output is correct |
26 |
Correct |
8 ms |
6492 KB |
Output is correct |
27 |
Correct |
7 ms |
6492 KB |
Output is correct |
28 |
Correct |
7 ms |
6492 KB |
Output is correct |
29 |
Correct |
8 ms |
6492 KB |
Output is correct |
30 |
Correct |
7 ms |
6492 KB |
Output is correct |
31 |
Correct |
7 ms |
6492 KB |
Output is correct |
32 |
Correct |
7 ms |
6584 KB |
Output is correct |
33 |
Correct |
7 ms |
6492 KB |
Output is correct |
34 |
Correct |
8 ms |
6492 KB |
Output is correct |
35 |
Correct |
12 ms |
6492 KB |
Output is correct |
36 |
Correct |
13 ms |
6492 KB |
Output is correct |
37 |
Correct |
14 ms |
6492 KB |
Output is correct |
38 |
Correct |
9 ms |
6748 KB |
Output is correct |
39 |
Correct |
10 ms |
6496 KB |
Output is correct |
40 |
Correct |
10 ms |
6744 KB |
Output is correct |