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>
typedef long long ll;
const ll MOD = 1e9 + 7;
ll F[1000010], ans;
int n, m;
ll pw(ll x, ll y){
ll ret = 1;
while(y){
if(y&1)ret = (ret * x) % MOD;
x = (x * x) % MOD;
y >>= 1;
}
return ret;
}
inline ll mul(ll x, ll y){return (x * y) % MOD;}
int main(){
scanf("%d%d",&n,&m);
if(m > n)m = n;
F[0] = F[1] = 1;
for(int i=2;i<=n;i++)F[i] = (F[i-1] * i) % MOD;
for(int i=0;i<m;i++){
ans += mul(mul(mul(mul(F[n], pw(F[i], MOD-2)), pw(F[n-i], MOD-2)), pw(m-i, n)), pw(-1, i));
ans = (ans + MOD) % MOD;
}
printf("%lld",ans);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |