标签:pre nbsp cat close efi bit type rac name
Lucas定理模版题
1 #include<bits/stdc++.h> 2 #define rep(i,l,r) for(int i=l;i<=r;++i) 3 using namespace std; 4 typedef long long ll; 5 const ll p=10007; 6 ll n,m,T; 7 ll Pow(int x,int y){ 8 if(!y)return 1; 9 ll t=Pow(x,y/2)%p; (t*=t)%=p; 10 if(y&1)return t*x;else return t; 11 } 12 ll c(ll n,ll m){ 13 if(n<m)return 0; 14 ll ans=1; 15 rep(i,1,m){ 16 ans=ans*(((n-m+i)%p)*Pow(i,p-2)%p)%p; 17 } 18 return ans; 19 } 20 ll lucas(ll n,ll m){ 21 if(!m)return 1; 22 return lucas(n/p,m/p)*c(n%p,m%p)%p; 23 } 24 int main(){ 25 cin>>T; 26 while(T--){ 27 cin>>n>>m; 28 cout<<lucas(n,m)<<endl; 29 } 30 }
标签:pre nbsp cat close efi bit type rac name
原文地址:http://www.cnblogs.com/Bloodline/p/6230947.html