#include <bits/stdc++.h> // PLEASE
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pp;
#define MAXN 100005
#define MAXM 1005
#define MAXP 25
#define A first
#define B second
#define MP make_pair
#define PB push_back
const ll INF = 2e9+13;
const ll MOD = 1e9+7;
int N, K;
ll fac[MAXN]; ll ifa[MAXN];
ll mmul(ll a, ll b) { return (a*b)%MOD; }
ll madd(ll a, ll b) { return (a+b)%MOD; }
ll nck(ll n, ll k)
{
return mmul(fac[n], mmul(ifa[n-k], ifa[k]));
}
ll pmod(ll a, ll b)
{
ll ret = 1LL;
while(b) {
if(b & 1) ret = mmul(ret, a);
a = mmul(a, a);
b /= 2LL;
}
return ret;
}
ll euler(ll n, ll m)
{
ll ans = 0;
for(int k=0; k<=m+1; k++) {
ll add = nck(n+1, k);
add = mmul(add, pmod(m+1-k, n));
if(k%2) ans = madd(ans, MOD-add);
else ans = madd(ans, add);
}
return ans;
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(0);
fac[0] = 1LL; ifa[0] = 1LL;
for(int i=1; i<MAXN; i++) {
fac[i] = mmul(fac[i-1], i);
ifa[i] = pmod(fac[i], MOD-2);
}
cin >> N >> K;
cout << euler(N, N-K) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1916 KB |
Output is correct |
2 |
Correct |
19 ms |
1916 KB |
Output is correct |
3 |
Correct |
19 ms |
1952 KB |
Output is correct |
4 |
Correct |
20 ms |
1960 KB |
Output is correct |
5 |
Correct |
19 ms |
2052 KB |
Output is correct |
6 |
Correct |
19 ms |
2072 KB |
Output is correct |
7 |
Correct |
19 ms |
2204 KB |
Output is correct |
8 |
Correct |
19 ms |
2300 KB |
Output is correct |
9 |
Correct |
20 ms |
2300 KB |
Output is correct |
10 |
Correct |
19 ms |
2300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1916 KB |
Output is correct |
2 |
Correct |
19 ms |
1916 KB |
Output is correct |
3 |
Correct |
19 ms |
1952 KB |
Output is correct |
4 |
Correct |
20 ms |
1960 KB |
Output is correct |
5 |
Correct |
19 ms |
2052 KB |
Output is correct |
6 |
Correct |
19 ms |
2072 KB |
Output is correct |
7 |
Correct |
19 ms |
2204 KB |
Output is correct |
8 |
Correct |
19 ms |
2300 KB |
Output is correct |
9 |
Correct |
20 ms |
2300 KB |
Output is correct |
10 |
Correct |
19 ms |
2300 KB |
Output is correct |
11 |
Correct |
22 ms |
2300 KB |
Output is correct |
12 |
Correct |
20 ms |
2300 KB |
Output is correct |
13 |
Correct |
19 ms |
2300 KB |
Output is correct |
14 |
Correct |
20 ms |
2304 KB |
Output is correct |
15 |
Correct |
19 ms |
2308 KB |
Output is correct |
16 |
Correct |
20 ms |
2440 KB |
Output is correct |
17 |
Correct |
19 ms |
2440 KB |
Output is correct |
18 |
Correct |
20 ms |
2440 KB |
Output is correct |
19 |
Correct |
20 ms |
2440 KB |
Output is correct |
20 |
Correct |
20 ms |
2440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1916 KB |
Output is correct |
2 |
Correct |
19 ms |
1916 KB |
Output is correct |
3 |
Correct |
19 ms |
1952 KB |
Output is correct |
4 |
Correct |
20 ms |
1960 KB |
Output is correct |
5 |
Correct |
19 ms |
2052 KB |
Output is correct |
6 |
Correct |
19 ms |
2072 KB |
Output is correct |
7 |
Correct |
19 ms |
2204 KB |
Output is correct |
8 |
Correct |
19 ms |
2300 KB |
Output is correct |
9 |
Correct |
20 ms |
2300 KB |
Output is correct |
10 |
Correct |
19 ms |
2300 KB |
Output is correct |
11 |
Correct |
22 ms |
2300 KB |
Output is correct |
12 |
Correct |
20 ms |
2300 KB |
Output is correct |
13 |
Correct |
19 ms |
2300 KB |
Output is correct |
14 |
Correct |
20 ms |
2304 KB |
Output is correct |
15 |
Correct |
19 ms |
2308 KB |
Output is correct |
16 |
Correct |
20 ms |
2440 KB |
Output is correct |
17 |
Correct |
19 ms |
2440 KB |
Output is correct |
18 |
Correct |
20 ms |
2440 KB |
Output is correct |
19 |
Correct |
20 ms |
2440 KB |
Output is correct |
20 |
Correct |
20 ms |
2440 KB |
Output is correct |
21 |
Correct |
22 ms |
2440 KB |
Output is correct |
22 |
Correct |
19 ms |
2440 KB |
Output is correct |
23 |
Correct |
20 ms |
2440 KB |
Output is correct |
24 |
Correct |
19 ms |
2440 KB |
Output is correct |
25 |
Correct |
19 ms |
2440 KB |
Output is correct |
26 |
Correct |
19 ms |
2440 KB |
Output is correct |
27 |
Correct |
20 ms |
2440 KB |
Output is correct |
28 |
Correct |
19 ms |
2440 KB |
Output is correct |
29 |
Correct |
19 ms |
2440 KB |
Output is correct |
30 |
Correct |
20 ms |
2440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1916 KB |
Output is correct |
2 |
Correct |
19 ms |
1916 KB |
Output is correct |
3 |
Correct |
19 ms |
1952 KB |
Output is correct |
4 |
Correct |
20 ms |
1960 KB |
Output is correct |
5 |
Correct |
19 ms |
2052 KB |
Output is correct |
6 |
Correct |
19 ms |
2072 KB |
Output is correct |
7 |
Correct |
19 ms |
2204 KB |
Output is correct |
8 |
Correct |
19 ms |
2300 KB |
Output is correct |
9 |
Correct |
20 ms |
2300 KB |
Output is correct |
10 |
Correct |
19 ms |
2300 KB |
Output is correct |
11 |
Correct |
22 ms |
2300 KB |
Output is correct |
12 |
Correct |
20 ms |
2300 KB |
Output is correct |
13 |
Correct |
19 ms |
2300 KB |
Output is correct |
14 |
Correct |
20 ms |
2304 KB |
Output is correct |
15 |
Correct |
19 ms |
2308 KB |
Output is correct |
16 |
Correct |
20 ms |
2440 KB |
Output is correct |
17 |
Correct |
19 ms |
2440 KB |
Output is correct |
18 |
Correct |
20 ms |
2440 KB |
Output is correct |
19 |
Correct |
20 ms |
2440 KB |
Output is correct |
20 |
Correct |
20 ms |
2440 KB |
Output is correct |
21 |
Correct |
22 ms |
2440 KB |
Output is correct |
22 |
Correct |
19 ms |
2440 KB |
Output is correct |
23 |
Correct |
20 ms |
2440 KB |
Output is correct |
24 |
Correct |
19 ms |
2440 KB |
Output is correct |
25 |
Correct |
19 ms |
2440 KB |
Output is correct |
26 |
Correct |
19 ms |
2440 KB |
Output is correct |
27 |
Correct |
20 ms |
2440 KB |
Output is correct |
28 |
Correct |
19 ms |
2440 KB |
Output is correct |
29 |
Correct |
19 ms |
2440 KB |
Output is correct |
30 |
Correct |
20 ms |
2440 KB |
Output is correct |
31 |
Correct |
30 ms |
2440 KB |
Output is correct |
32 |
Correct |
29 ms |
2440 KB |
Output is correct |
33 |
Correct |
29 ms |
2440 KB |
Output is correct |
34 |
Correct |
28 ms |
2440 KB |
Output is correct |
35 |
Correct |
21 ms |
2440 KB |
Output is correct |
36 |
Correct |
22 ms |
2440 KB |
Output is correct |
37 |
Correct |
21 ms |
2440 KB |
Output is correct |
38 |
Correct |
21 ms |
2440 KB |
Output is correct |
39 |
Correct |
23 ms |
2440 KB |
Output is correct |
40 |
Correct |
25 ms |
2440 KB |
Output is correct |