# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
21295 | suzy | 순열 (kriii4_T) | C++14 | 369 ms | 8928 KiB |
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 <stdio.h>
#define MOD 1000000007
typedef long long lli;
lli fac[1000002];
lli pw(lli n, lli x) {
if(x==0) return 1;
if(x%2) return n*pw(n,x-1)%MOD;
else { lli ret=pw(n,x/2); return ret*ret%MOD; }
}
int main() {
lli n, k;
fac[0]=1;
for(lli i=1;i<=1000001;i++)
fac[i]=fac[i-1]*i%MOD;
scanf("%lld %lld",&n,&k); k++;
if(k>n) {
puts("0"); return 0;
}
lli res=0, ncl=fac[n+1]*pw(fac[n-k],MOD-2)%MOD*pw(fac[k+1],MOD-2)%MOD;
for(lli l=k;l<=n;l++) {
res+=(n-l+1)*fac[l]%MOD*fac[n-l]%MOD*ncl%MOD;
res%=MOD;
ncl=ncl*(n-l)%MOD*pw(l+2,MOD-2)%MOD;
}
printf("%lld\n",res);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |