【数论定理】卢卡斯定理
2016-08-05 16:57
204 查看
库卡斯模板:
/* Lucas定理:我们令n=sp+q , m=tp+r .(q ,r ≤p) * 那么:C(n,m)=C(s,t)*C(q,r) * 使用前要打出0~mod-1的阶乘表fac[] * 时间O(logp(n)*p) */ const int mod=1000000007; typedef long long ll; ll fac[100018]; ll pow_m(ll a,ll n) { ll res=1; while(n) { if(n%2) res*=a,res%=mod; a=a*a; a%=mod; n/=2; } return res; } ll inv(ll a,ll mod) { return pow_m(a,mod-2); } ll C(ll n,ll m) { if(n<m) return 0; return (fac *inv(fac[m],mod)%mod)*inv(fac[n-m],mod)%mod; } ll lucas(ll n,ll m,ll mod) { ll res=0; if(n+m==0) return 1; return C(n%mod,m%mod)*lucas(n/mod,m/mod,mod)%mod; }
相关文章推荐
- 【Luogu3807】【模板】卢卡斯定理(数论)
- hdu5698百度之星瞬间移动(数论/卢卡斯定理)
- 数论-Lucas(卢卡斯定理)
- ACM数论之旅10---大组合数-卢卡斯定理(在下卢卡斯,你是我的Master吗?(。-`ω´-) )
- 数论-Lucas(卢卡斯定理)
- 数论继续学习10---大组合数-卢卡斯定理
- 教你一波Lucas(卢卡斯)定理在数论解题中的应用
- 数论---同余法则定理
- 数论中的若干定理
- Codeforces 711E ZS and The Birthday Paradox 数论(Legendre's定理)
- 数论定理
- 卢卡斯定理&扩展卢卡斯定理
- 数论之Lucas定理及证明过程
- zzuli 2182 不是签到题XD【数论定理】
- 17.8.27 校内赛 解题报告【卢卡斯定理】【dfs+hash】【线段树】
- 「LibreOJ β Round #4」多项式 (广义欧拉数论定理)
- 初等数论四大定理之——费马小定理
- 欧几里得算法和唯一分解定理(数论)
- 51nod 1120 机器人走方格V3【卡特兰数】【卢卡斯定理】
- 数论中的若干定理及证明