Lucas定理模版、
来源:互联网 发布:网络分线器怎么用 编辑:程序博客网 时间:2024/05/17 00:09
资料:传送门
相关题目:传送门
求C(n,m)模p的结果
#include<cmath>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;typedef long long ll;ll n,m,p;ll quick_mod(ll a, ll b){ll ans = 1;a=a%p;while(b){if(b&1)ans = ans*a%p;b>>=1;a=a*a%p;}return ans;}ll C(ll n, ll m){if(m>n)return 0;if(n==m)return 1;if(m>n-m)m = n-m;ll ans=1, cns=1;for(int i=1; i<=m; ++i){ans=(ans*(n+i-m))%p;cns=(cns*i)%p;}ll res = (ans*quick_mod(cns, p-2))%p;return res;}ll Lucas(ll n, ll m){if(m==0)return 1;return C(n%p, m%p)%p * Lucas(n/p, m/p)%p;}int main(){scanf("%lld%lld%lld",&n,&m,&p);printf("%lld\n", Lucas(n, m));return 0; }
0 0
- Lucas定理模版、
- FZU 2020 组合数取模(Lucas定理模版)
- xdoj 1227 Godv的数列(lucas,扩展lucas,中国剩余定理模版)
- Lucas 定理
- Lucas 定理
- lucas定理
- Lucas定理
- Lucas 定理
- Lucas 定理
- Lucas 定理
- Lucas 定理
- Lucas定理
- lucas定理
- lucas定理
- Lucas定理
- Lucas定理
- Lucas 定理。。。
- lucas定理
- JS与安卓的通信
- NOIP2015 提高组 day1 信息传递
- Java中不编写返回引用对象的访问器方法
- yii2 高级版 多版本支持
- DOM Element对象的offsetXXX方法
- Lucas定理模版、
- Android联系人数据库读取
- 【mysql】事务死锁问题
- Android之利用android:indeterminateDrawable来实现ProgressBar三种方式
- 视图和表
- mysql主从复制原理
- 第二周-项目1C/C++语言中函数参数传递的三种方式
- LCA+RMQ求树中两点距离
- POJ 2112 Optimal Milking 网络流初步