//Smaug never desolated!!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = (int)1e5 + 7;
const int infint = (int)1e8 + 3;
const int MOD = (int)1e9 + 7;
const ll inf = (ll)1e18;
ll fact[MAXN], facrev[MAXN], n, k;
ll pwr(ll a, ll b)
{
if(b == 0)
return 1;
if(b == 1)
return a;
ll c = pwr(a, b / 2);
c = (c * c) % MOD;
if(b % 2)
c = (c * a) % MOD;
return c;
}
ll inv(ll p)
{
return pwr(p, MOD - 2);
}
ll C(ll n, ll k)
{
ll mul = fact[n];
mul = (mul * facrev[k]) % MOD;
mul = (mul * facrev[n - k]) % MOD;
return mul;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> k;
fact[0] = 1;
for (int i = 1; i < MAXN; i++)
fact[i] = (fact[i - 1] * i) % MOD;
for (int i = MAXN - 1; i >= 0; i--)
facrev[i] = inv(fact[i]);
ll ans = 0;
for (int j = 0; j <= k; j++)
{
ll cur = pwr(k - j, n) * C(n + 1, j) % MOD;
if(j % 2 == 0)
ans = (ans + cur) % MOD;
else
ans = (ans - cur + MOD) % MOD;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
1920 KB |
Output is correct |
2 |
Correct |
28 ms |
1912 KB |
Output is correct |
3 |
Correct |
28 ms |
2012 KB |
Output is correct |
4 |
Correct |
28 ms |
1912 KB |
Output is correct |
5 |
Correct |
28 ms |
1912 KB |
Output is correct |
6 |
Correct |
29 ms |
1912 KB |
Output is correct |
7 |
Correct |
28 ms |
1912 KB |
Output is correct |
8 |
Correct |
28 ms |
1912 KB |
Output is correct |
9 |
Correct |
27 ms |
1912 KB |
Output is correct |
10 |
Correct |
28 ms |
2040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
1920 KB |
Output is correct |
2 |
Correct |
28 ms |
1912 KB |
Output is correct |
3 |
Correct |
28 ms |
2012 KB |
Output is correct |
4 |
Correct |
28 ms |
1912 KB |
Output is correct |
5 |
Correct |
28 ms |
1912 KB |
Output is correct |
6 |
Correct |
29 ms |
1912 KB |
Output is correct |
7 |
Correct |
28 ms |
1912 KB |
Output is correct |
8 |
Correct |
28 ms |
1912 KB |
Output is correct |
9 |
Correct |
27 ms |
1912 KB |
Output is correct |
10 |
Correct |
28 ms |
2040 KB |
Output is correct |
11 |
Correct |
28 ms |
1916 KB |
Output is correct |
12 |
Correct |
28 ms |
1912 KB |
Output is correct |
13 |
Correct |
29 ms |
1912 KB |
Output is correct |
14 |
Correct |
29 ms |
1912 KB |
Output is correct |
15 |
Correct |
29 ms |
1936 KB |
Output is correct |
16 |
Correct |
30 ms |
1912 KB |
Output is correct |
17 |
Correct |
28 ms |
1884 KB |
Output is correct |
18 |
Correct |
28 ms |
1912 KB |
Output is correct |
19 |
Correct |
29 ms |
1884 KB |
Output is correct |
20 |
Correct |
28 ms |
1912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
1920 KB |
Output is correct |
2 |
Correct |
28 ms |
1912 KB |
Output is correct |
3 |
Correct |
28 ms |
2012 KB |
Output is correct |
4 |
Correct |
28 ms |
1912 KB |
Output is correct |
5 |
Correct |
28 ms |
1912 KB |
Output is correct |
6 |
Correct |
29 ms |
1912 KB |
Output is correct |
7 |
Correct |
28 ms |
1912 KB |
Output is correct |
8 |
Correct |
28 ms |
1912 KB |
Output is correct |
9 |
Correct |
27 ms |
1912 KB |
Output is correct |
10 |
Correct |
28 ms |
2040 KB |
Output is correct |
11 |
Correct |
28 ms |
1916 KB |
Output is correct |
12 |
Correct |
28 ms |
1912 KB |
Output is correct |
13 |
Correct |
29 ms |
1912 KB |
Output is correct |
14 |
Correct |
29 ms |
1912 KB |
Output is correct |
15 |
Correct |
29 ms |
1936 KB |
Output is correct |
16 |
Correct |
30 ms |
1912 KB |
Output is correct |
17 |
Correct |
28 ms |
1884 KB |
Output is correct |
18 |
Correct |
28 ms |
1912 KB |
Output is correct |
19 |
Correct |
29 ms |
1884 KB |
Output is correct |
20 |
Correct |
28 ms |
1912 KB |
Output is correct |
21 |
Correct |
29 ms |
1916 KB |
Output is correct |
22 |
Correct |
28 ms |
1916 KB |
Output is correct |
23 |
Correct |
28 ms |
1912 KB |
Output is correct |
24 |
Correct |
28 ms |
1912 KB |
Output is correct |
25 |
Correct |
28 ms |
1912 KB |
Output is correct |
26 |
Correct |
28 ms |
1912 KB |
Output is correct |
27 |
Correct |
29 ms |
1912 KB |
Output is correct |
28 |
Correct |
29 ms |
1912 KB |
Output is correct |
29 |
Correct |
28 ms |
1912 KB |
Output is correct |
30 |
Correct |
28 ms |
1912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
1920 KB |
Output is correct |
2 |
Correct |
28 ms |
1912 KB |
Output is correct |
3 |
Correct |
28 ms |
2012 KB |
Output is correct |
4 |
Correct |
28 ms |
1912 KB |
Output is correct |
5 |
Correct |
28 ms |
1912 KB |
Output is correct |
6 |
Correct |
29 ms |
1912 KB |
Output is correct |
7 |
Correct |
28 ms |
1912 KB |
Output is correct |
8 |
Correct |
28 ms |
1912 KB |
Output is correct |
9 |
Correct |
27 ms |
1912 KB |
Output is correct |
10 |
Correct |
28 ms |
2040 KB |
Output is correct |
11 |
Correct |
28 ms |
1916 KB |
Output is correct |
12 |
Correct |
28 ms |
1912 KB |
Output is correct |
13 |
Correct |
29 ms |
1912 KB |
Output is correct |
14 |
Correct |
29 ms |
1912 KB |
Output is correct |
15 |
Correct |
29 ms |
1936 KB |
Output is correct |
16 |
Correct |
30 ms |
1912 KB |
Output is correct |
17 |
Correct |
28 ms |
1884 KB |
Output is correct |
18 |
Correct |
28 ms |
1912 KB |
Output is correct |
19 |
Correct |
29 ms |
1884 KB |
Output is correct |
20 |
Correct |
28 ms |
1912 KB |
Output is correct |
21 |
Correct |
29 ms |
1916 KB |
Output is correct |
22 |
Correct |
28 ms |
1916 KB |
Output is correct |
23 |
Correct |
28 ms |
1912 KB |
Output is correct |
24 |
Correct |
28 ms |
1912 KB |
Output is correct |
25 |
Correct |
28 ms |
1912 KB |
Output is correct |
26 |
Correct |
28 ms |
1912 KB |
Output is correct |
27 |
Correct |
29 ms |
1912 KB |
Output is correct |
28 |
Correct |
29 ms |
1912 KB |
Output is correct |
29 |
Correct |
28 ms |
1912 KB |
Output is correct |
30 |
Correct |
28 ms |
1912 KB |
Output is correct |
31 |
Correct |
29 ms |
1912 KB |
Output is correct |
32 |
Correct |
29 ms |
1872 KB |
Output is correct |
33 |
Correct |
29 ms |
1912 KB |
Output is correct |
34 |
Correct |
30 ms |
1912 KB |
Output is correct |
35 |
Correct |
38 ms |
1956 KB |
Output is correct |
36 |
Correct |
41 ms |
1912 KB |
Output is correct |
37 |
Correct |
40 ms |
1960 KB |
Output is correct |
38 |
Correct |
29 ms |
1912 KB |
Output is correct |
39 |
Correct |
32 ms |
1912 KB |
Output is correct |
40 |
Correct |
34 ms |
1916 KB |
Output is correct |