lucas number theory

Perm arranged counted from sad

 

lucas said

C(n,m)%p=C(n%p,m%p)*C(n/p,m/p)%p

Ever since

In the case of a good mind not to engage in proof of principle

Resulting in a morning PermWA

 1 ll pow(ll a,ll b){
 2     ll ans=1;
 3     while(b){
 4         if(b&1)ans=(ans*a)%p;
 5         a=(a*a)%p;
 6         b>>=1;
 7     }
 8     return ans%p;
 9 }
10 ll C(int a,int b){
11     if(a<b)return 0;
12     if(b==0)return 1;
13     return jc[a]*pow(jc[a-b]*jc[b]%p,p-2)%p;
14 }
15 ll lucas(int a,int b){
16     if(b>a)return 0;
17     if(b==0)return 1;
18     if(a>p||b>p)return C(a%p,b%p)*lucas(a/p,b/p)%p;
19     return C(a,b)%p;
20 }
21         jc[0]=1;
22     for(int i=1;i<=n;++i)jc[i]=jc[i-1]*1ll*i%p;    
View Code

Note: {

  (1) that is capable mod mod

    Code multiplication is mainly

    It is easy to burst long long

  (2) Tokuban:

    m==0 return 1;

    n<m return 0;

  (3) lucas details

    Only when

    n> mod || m> mod only lucas    

}

At last

Recommend inverse linear push

I'm too lazy

He took quickly make up a modulo exponentiation

Guess you like

Origin www.cnblogs.com/2018hzoicyf/p/11112804.html