暴力算组合数,算个逆元就好了。
费马小定理和扩欧都可以。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#define ll long long
using namespace std;
ll ksm(ll a,ll b,ll p){
a%=p;
ll ans=1;
while(b){
if(b&1){
ans=(ans*a)%p;
}
a=a*a%p;
b>>=1;
}
return ans;
}
ll a[200001];
ll p=1e9+7;
int main(){
freopen("video.in","r",stdin);
freopen("video.out","w",stdout);
a[1]=1;a[0]=1;
for(ll i=1;i<=200000;i++){
a[i]=(a[i-1]*i)%p;
}
int n,m;
scanf("%d %d",&n,&m);
ll ans=1;
ans=(ans*a[n])%p;
ans=(ans*ksm(a[n-m],p-2,p))%p;
ans=(ans*ksm(a[m],p-2,p))%p;
printf("%lld",ans);
return 0;
}