This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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);
| ~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |