lucus求解组合数的时间复杂度为
O(MODlogn(MOD))
适用于MOD较小但n较大的情况
模板:
LL MOD=1e6+3; LL QuickExp(LL base,LL exp) { LL res=1; while(exp) { if(exp&1) { res*=base; res%=MOD; } base*=base; base%=MOD; exp>>=1; } return res; } LL C(LL n,LL k) { if(n<k) return 0; LL up=1,down=1; for(int i=1;i<=n-k;i++) { down=down*i%MOD; up=up*(n-i+1)%MOD; } return up*QuickExp(down,MOD-2)%MOD; } LL Lucas(LL a,LL b) { if(a<MOD&&b<MOD) return C(a,b); else return Lucas(a/MOD,b/MOD)*C(a%MOD,b%MOD)%MOD; }View Code
标签:lucas,求解,res,LL,base,exp,MOD From: https://www.cnblogs.com/ydUESTC/p/16769012.html