#include<bits/stdc++.h>
#define ll long long
const int inf=1e9;
#define mod 1000000007
using namespace std;
int fact[200005],inv[200005];
int po(int b,int e)
{
int p=1;
while(e){
if (e%2==1)
p=1LL*p*b%mod;
b=1LL*b*b%mod;
e=e/2;
}
return p;
}
int comb(int n,int k)
{
return 1LL*fact[n]*inv[k]%mod*inv[n-k]%mod;
}
int calc(int n,int k)
{
if (k>n)
return 0;
int ans=0,i;
for(i=0;i<=k;i++){
int aux=1LL*comb(n+1,i)*po(k+1-i,n)%mod;
if (i%2==1)
ans=(ans-aux+mod)%mod;
else
ans=(ans+aux)%mod;
}
return ans;
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int n,k,i;
fact[0]=1;
for(i=1;i<=200000;i++)
fact[i]=1LL*fact[i-1]*i%mod;
inv[200000]=po(fact[200000],mod-2);
for(i=199999;i>=0;i--)
inv[i]=1LL*inv[i+1]*(i+1)%mod;
scanf("%d%d",&n,&k);
printf("%d\n",calc(n,k-1));
return 0;
}
Compilation message
asceticism.cpp: In function 'int main()':
asceticism.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
47 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1868 KB |
Output is correct |
2 |
Correct |
4 ms |
1868 KB |
Output is correct |
3 |
Correct |
4 ms |
1868 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
4 ms |
1868 KB |
Output is correct |
6 |
Correct |
4 ms |
1868 KB |
Output is correct |
7 |
Correct |
4 ms |
1792 KB |
Output is correct |
8 |
Correct |
4 ms |
1860 KB |
Output is correct |
9 |
Correct |
4 ms |
1868 KB |
Output is correct |
10 |
Correct |
4 ms |
1868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1868 KB |
Output is correct |
2 |
Correct |
4 ms |
1868 KB |
Output is correct |
3 |
Correct |
4 ms |
1868 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
4 ms |
1868 KB |
Output is correct |
6 |
Correct |
4 ms |
1868 KB |
Output is correct |
7 |
Correct |
4 ms |
1792 KB |
Output is correct |
8 |
Correct |
4 ms |
1860 KB |
Output is correct |
9 |
Correct |
4 ms |
1868 KB |
Output is correct |
10 |
Correct |
4 ms |
1868 KB |
Output is correct |
11 |
Correct |
4 ms |
1868 KB |
Output is correct |
12 |
Correct |
4 ms |
1864 KB |
Output is correct |
13 |
Correct |
4 ms |
1864 KB |
Output is correct |
14 |
Correct |
4 ms |
1740 KB |
Output is correct |
15 |
Correct |
4 ms |
1860 KB |
Output is correct |
16 |
Correct |
4 ms |
1868 KB |
Output is correct |
17 |
Correct |
4 ms |
1864 KB |
Output is correct |
18 |
Correct |
6 ms |
1868 KB |
Output is correct |
19 |
Correct |
5 ms |
1868 KB |
Output is correct |
20 |
Correct |
5 ms |
1864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1868 KB |
Output is correct |
2 |
Correct |
4 ms |
1868 KB |
Output is correct |
3 |
Correct |
4 ms |
1868 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
4 ms |
1868 KB |
Output is correct |
6 |
Correct |
4 ms |
1868 KB |
Output is correct |
7 |
Correct |
4 ms |
1792 KB |
Output is correct |
8 |
Correct |
4 ms |
1860 KB |
Output is correct |
9 |
Correct |
4 ms |
1868 KB |
Output is correct |
10 |
Correct |
4 ms |
1868 KB |
Output is correct |
11 |
Correct |
4 ms |
1868 KB |
Output is correct |
12 |
Correct |
4 ms |
1864 KB |
Output is correct |
13 |
Correct |
4 ms |
1864 KB |
Output is correct |
14 |
Correct |
4 ms |
1740 KB |
Output is correct |
15 |
Correct |
4 ms |
1860 KB |
Output is correct |
16 |
Correct |
4 ms |
1868 KB |
Output is correct |
17 |
Correct |
4 ms |
1864 KB |
Output is correct |
18 |
Correct |
6 ms |
1868 KB |
Output is correct |
19 |
Correct |
5 ms |
1868 KB |
Output is correct |
20 |
Correct |
5 ms |
1864 KB |
Output is correct |
21 |
Correct |
4 ms |
1868 KB |
Output is correct |
22 |
Correct |
4 ms |
1868 KB |
Output is correct |
23 |
Correct |
4 ms |
1868 KB |
Output is correct |
24 |
Correct |
4 ms |
1868 KB |
Output is correct |
25 |
Correct |
4 ms |
1868 KB |
Output is correct |
26 |
Correct |
4 ms |
1868 KB |
Output is correct |
27 |
Correct |
4 ms |
1868 KB |
Output is correct |
28 |
Correct |
4 ms |
1868 KB |
Output is correct |
29 |
Correct |
4 ms |
1740 KB |
Output is correct |
30 |
Correct |
4 ms |
1872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1868 KB |
Output is correct |
2 |
Correct |
4 ms |
1868 KB |
Output is correct |
3 |
Correct |
4 ms |
1868 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
4 ms |
1868 KB |
Output is correct |
6 |
Correct |
4 ms |
1868 KB |
Output is correct |
7 |
Correct |
4 ms |
1792 KB |
Output is correct |
8 |
Correct |
4 ms |
1860 KB |
Output is correct |
9 |
Correct |
4 ms |
1868 KB |
Output is correct |
10 |
Correct |
4 ms |
1868 KB |
Output is correct |
11 |
Correct |
4 ms |
1868 KB |
Output is correct |
12 |
Correct |
4 ms |
1864 KB |
Output is correct |
13 |
Correct |
4 ms |
1864 KB |
Output is correct |
14 |
Correct |
4 ms |
1740 KB |
Output is correct |
15 |
Correct |
4 ms |
1860 KB |
Output is correct |
16 |
Correct |
4 ms |
1868 KB |
Output is correct |
17 |
Correct |
4 ms |
1864 KB |
Output is correct |
18 |
Correct |
6 ms |
1868 KB |
Output is correct |
19 |
Correct |
5 ms |
1868 KB |
Output is correct |
20 |
Correct |
5 ms |
1864 KB |
Output is correct |
21 |
Correct |
4 ms |
1868 KB |
Output is correct |
22 |
Correct |
4 ms |
1868 KB |
Output is correct |
23 |
Correct |
4 ms |
1868 KB |
Output is correct |
24 |
Correct |
4 ms |
1868 KB |
Output is correct |
25 |
Correct |
4 ms |
1868 KB |
Output is correct |
26 |
Correct |
4 ms |
1868 KB |
Output is correct |
27 |
Correct |
4 ms |
1868 KB |
Output is correct |
28 |
Correct |
4 ms |
1868 KB |
Output is correct |
29 |
Correct |
4 ms |
1740 KB |
Output is correct |
30 |
Correct |
4 ms |
1872 KB |
Output is correct |
31 |
Correct |
4 ms |
1868 KB |
Output is correct |
32 |
Correct |
4 ms |
1868 KB |
Output is correct |
33 |
Correct |
5 ms |
1824 KB |
Output is correct |
34 |
Correct |
7 ms |
1868 KB |
Output is correct |
35 |
Correct |
13 ms |
1860 KB |
Output is correct |
36 |
Correct |
14 ms |
1868 KB |
Output is correct |
37 |
Correct |
16 ms |
1740 KB |
Output is correct |
38 |
Correct |
5 ms |
1864 KB |
Output is correct |
39 |
Correct |
7 ms |
1740 KB |
Output is correct |
40 |
Correct |
8 ms |
1868 KB |
Output is correct |