数论--Lucas Theorem
来源:互联网 发布:linux http proxy 编辑:程序博客网 时间:2024/06/05 17:13
此定理用来求
适用:大的组合数取模。
定理给出:
详细证明参见 Wikipedia: Lucas’ theorem
代码实现(hdoj–3037):
#include <iostream>#include <cmath>#include <algorithm>using namespace std;// 1856MS 2584Ktypedef long long ll;const int maxn = 100010;ll f[maxn];int t, n, m, p;void init(ll p){ f[0] = 1; for(int i = 1; i <= p; ++i) f[i] = f[i - 1] * i % p;}//求逆元ll inv(ll a, ll m){ if(a == 1) return 1; return inv(m % a, m) * (m - m / a) % m;}ll pow(ll a, ll b, ll p){ ll res = 1; while(b){ if(b & 1) res = res * a % p; a = a * a % p; b >>= 1; } return res;}ll Lucas(ll n, ll m, ll p){ ll ans = 1; while( n && m ) { ll a = n % p; ll b = m % p; if(a < b) return 0; //两者皆可 //ans = (ans * f[a] % p) * inv(f[b] * f[a - b] % p, p) % p; ans = ans * f[a] * pow(f[b] * f[a - b] % p, p - 2, p) % p; n /= p; m /= p; } return ans;}int main(){ for(cin >> t; t--; ){ cin >> n >> m >> p; init(p); cout << Lucas(n + m, m, p) << endl; } return 0;}
0 0
- 数论--Lucas Theorem
- Lucas' theorem
- lucas数论定理学习
- 数论 Lucas定理 hdu3037
- 4176: Lucas的数论
- bzoj4176 Lucas 的数论
- 数论总结之Lucas
- lucas (数论定理)
- [bzoj4176]Lucas的数论
- Chinese remainder theorem again + 数论
- bzoj 4176 Lucas的数论
- 数论-Lucas(卢卡斯定理)
- BZOJ 4176 Lucas的数论
- [杜教筛] BZOJ4176. Lucas的数论
- HDU 1788 Chinese remainder theorem again 数论
- 【数论】 HDOJ 1788 Chinese remainder theorem again
- HDOJ-1788 Chinese remainder theorem again(数论)
- HDU 6124 Euler theorem(数论)
- 数据库真的成为瓶颈了
- Java中访问权限的等级
- 进程上下文VS中断上下文
- lintcode之 合并排序数组 II
- ffmpeg中的pcm格式
- 数论--Lucas Theorem
- 关于Curator学习过程问题
- spring mvc ajax 请求返回json数据
- A20平台固件解包打包
- 聪明的kk
- React Native中的事件
- android 判断控件是否在屏幕范围内 是否可见
- Android ListView 使用相关技巧
- iOS UILabel垂直居中