https://blog.csdn.net/sr_19930829/article/details/39058487

 LL Lucas(LL n, LL m, int p){
return m ? Lucas(n/p, m/p, p) * comb(n%p, m%p, p) % p : ;
}

Saving Beans HDU3037

#include <iostream>
#include <string.h>
#include <cmath>
using namespace std;
typedef long long ll;
const int maxm = 1e5 + ;
ll fac[maxm]; void init(ll p) {
fac[]=;
for(int i = ; i <= p; i++)
fac[i] = fac[i - ] * i % p;
} ll qpow(ll x, ll n, ll mod) {
ll res = ;
while (n > ) {
if (n & ) {
res = res * x % mod;
}
x = x * x % mod;
n >>= ;
}
return res;
} ll lucas(ll n, ll m, ll p)
{
ll res = ;
while(n && m)
{
ll a = n % p;
ll b = m % p;
if(a < b) return ;
res = (res * fac[a] * qpow(fac[b] * fac[a - b] % p, p - , p)) % p;
n /= p;
m /= p;
}
return res;
} int t;
ll n, m, p;
int main() {
scanf("%d", &t);
while(t--) {
scanf("%lld%lld%lld", &n, &m, &p);
init(p);
printf("%lld\n", lucas(n + m, m, p));
}
return ;
}

大组合数Lucas的更多相关文章

  1. Lucas 大组合数

    题目:HDU 3037 题意:有n个树,m个坚果,放到n个树里,可以不放完,有多少种方法. 分析: 得到组合数了. 大组合数什么费马小定理,Lucas定理都来了: 总的说,不能用二维地推了,用的却是组 ...

  2. 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1<p<=1e6,p必须为素数

    typedef long long ll; /********************************** 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1&l ...

  3. uoj86 mx的组合数 (lucas定理+数位dp+原根与指标+NTT)

    uoj86 mx的组合数 (lucas定理+数位dp+原根与指标+NTT) uoj 题目描述自己看去吧( 题解时间 首先看到 $ p $ 这么小还是质数,第一时间想到 $ lucas $ 定理. 注意 ...

  4. lucas定理解决大组合数取模

    LL MyPow(LL a, LL b) { LL ret = ; while (b) { ) ret = ret * a % MOD; a = a * a % MOD; b >>= ; ...

  5. 大组合数:Lucas定理

    最近碰到一题,问你求mod (p1*p2*p3*……*pl) ,其中n和m数据范围是1~1e18 , l ≤10 , pi ≤ 1e5为不同的质数,并保证M=p1*p2*p3*……*pl ≤ 1e18 ...

  6. [Swust OJ 247]--皇帝的新衣(组合数+Lucas定理)

    题目链接:http://acm.swust.edu.cn/problem/0247/ Time limit(ms): 1000 Memory limit(kb): 65535   Descriptio ...

  7. 【BZOJ-4591】超能粒子炮·改 数论 + 组合数 + Lucas定理

    4591: [Shoi2015]超能粒子炮·改 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 95  Solved: 33[Submit][Statu ...

  8. HDU 5698 大组合数取模(逆元)

    瞬间移动 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  9. luogu4345 [SHOI2015]超能粒子炮·改(组合数/Lucas定理)

    link 输入\(n,k\),求\(\sum_{i=0}^k{n\choose i}\)对2333取模,10万组询问,n,k<=1e18 注意到一个2333这个数字很小并且还是质数这一良好性质, ...

随机推荐

  1. OpenCV3+VS2015 经常出现debug error abort()has been called问题

    方案1:图片路径错误:查看imread的路径

  2. ubuntu 安装 lnmp 参考

    暂时参考 https://blog.csdn.net/weixin_36025897/article/details/81417458 https://www.jianshu.com/p/37cacd ...

  3. 少年的u

    发现了我提取DNa的过程存在问题,能够跑出action 但是不能克隆出基因.老师给我解释了为什么,说是我的DNA质量不是很高.但是在接下来的时间我会解决这个问题. 和师姐一起去上面的实验室,看了定量P ...

  4. AcWing 1019. 庆功会 多重背包求max

    //多重背包 max #include <iostream> using namespace std; ; int n, m; int f[N]; int main() { cin > ...

  5. AcWing 1020. 潜水员 二维费用背包

    //体积最多是j 全部为0,v>=0 //体积恰好为j f[0][0]=0,f[i]=无穷,v>=0 //体积至少是j f[0][0]=0,f[i]=无穷,体积为负数时于0取大 #incl ...

  6. Go_初始化是否为nil

    package main import ( "fmt" ) func main() { //基本数据类型(默认值) var a int fmt.Println(a) //0 a = ...

  7. 【Python】字符串操作符

  8. (转)数据索引BTree

    .B-tree 转自:http://blog.csdn.net/hbhhww/article/details/8206846 B-tree又叫平衡多路查找树.一棵m阶的B-tree (m叉树)的特性如 ...

  9. tp5.0和tp3.2的区别

    1. 控制器输出return $this->fetch(); ----5$this->display(); ----3.2 单字母函数去掉了 如:M() D() U() S() C() 3 ...

  10. 数据库之一、数据库简介及SQL概要

    1.数据库简介: 数据库(Database,DB)是一个长期存储在计算机内的.有组织的.有共享的.统一管理的数据集合.简单来讲就是可以放大量数据的地方.管理数据库的计算机系统称为数据库管理系统(Dat ...