1 ll PowMod(ll a,ll b,ll MOD){ 2 ll ret=1; 3 while(b){ 4 if(b&1) ret=(ret*a)%MOD; 5 a=(a*a)%MOD; 6 b>>=1; 7 } 8 return ret; 9 } 10 ll fac[110219]; 11 ll Get_Fact(ll p) 12 { 13 fac[0]=1; 14 for(int i=1;i<=p;i++) 15 fac[i]=(fac[i-1]*i)%p; 16 } 17 ll Lucas(ll n,ll m,ll p){ 18 ll ret=1; 19 while(n&&m){ 20 ll a=n%p,b=m%p; 21 if(a<b) return 0; 22 ret=(ret*fac[a]*PowMod(fac[b]*fac[a-b]%p,p-2,p))%p; 23 n/=p; 24 m/=p; 25 } 26 return ret; 27 }