1 ll exgcd(ll a,ll b,ll &x,ll &y) 2 { 3 if(b==0) 4 { 5 x=1,y=0; 6 return a; 7 } 8 ll res=exgcd(b,a%b,y,x); 9 y-=a/b*x; 10 return res; 11 } 12 13 ll Inv(ll a) 14 { 15 ll d,x,y; 16 d=exgcd(a,mod,x,y); 17 if(d==1) 18 return (x%mod+mod)%mod; 19 return -1; 20 } 21 22 ll C(ll n,ll m) 23 { 24 ll ans1=1,ans2=1; 25 for(int i=n,j=1;j<=m;j++,i--) 26 { 27 ans1=ans1*i%mod; 28 ans2=ans2*j%mod; 29 } 30 return (ll)(ans1*Inv(ans2)%mod); 31 }
C(4,2)=6,记得Define mod