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 int long long
const int mod=1e9+7LL;
using namespace std;
int n,k,fact[100005],inv[100005],invfact[100005],ans;
int fp(int x,int p){
if (!p) return 1LL;
int t=fp(x,p/2);
t=(t*t)%mod;
if (p&1LL) t*=x;
return t%mod;
}
int ncr(int x,int p){
return (fact[x]*invfact[p]%mod*invfact[x-p])%mod;
}
signed main(){
cin>>n>>k;
fact[0]=1LL;
k=n-k;
for (int i=1;i<=n+1;i++) fact[i]=(fact[i-1]*i)%mod;
inv[1]=invfact[0]=invfact[1]=1LL;
for (int i=2;i<=n+1;i++){
inv[i]=mod-mod/i*inv[mod%i]%mod;
invfact[i]=(invfact[i-1]*inv[i])%mod;
}
for (int i=0;i<=k;i++){
int cal=ncr(n+1,i)*fp(k+1LL-i,n)%mod;
if (i&1LL) ans+=(mod-cal);
else ans+=cal;
ans%=mod;
}
cout<<ans%mod<<"\n";
}
# | 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... |