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. C#中常见的winform控件命名规范 转

    我们知道Button 常常简称为btn,那么Winform中的其它控件呢,这篇文章在C#的winform控件命名规范 的基础上对一些控件的名称的简称进行了整理. 1. 标准控件 NO. 控件类型简写 ...

  2. python:文件、目录遍历器

    #!/usr/bin/python# -*- coding:utf-8 -*- import osimport json file = open('a.txt','w')for root,dirs,f ...

  3. Web测试控件测试点总结

    1. https://www.testwo.com/blog/344  文本输入框测试用例 验证输入框是否trim处理 注:trim()函数作用是 去掉字符序列左边和右边的空格,中间的空格不管.如果字 ...

  4. 环境配置 | mac环境变量文件.bash_profile相关

    每次环境配置都费老劲,零零碎碎的知识就记在这里 文件:~/.bash_profile

  5. conn (php)

    <?php$host="localhost";$db_user="root"; //数据库用户$db_pass=""; //数据库密码 ...

  6. 2019牛客多校第七场E Find the median 离散化+线段树维护区间段

    Find the median 题意 刚开始集合为空,有n次操作,每次操作往集合里面插入[L[i],R[i]]的值,问每次操作后中位数是多少 分析 由于n比较大,并且数可以达到1e9,我们无法通过权值 ...

  7. 在多租户(容器)数据库中如何创建PDB:方法3 克隆远程PDB

    基于版本:19c (12.2.0.3) AskScuti 创建方法:克隆远程PDB(从非当前CDB中进行远程克隆).将 CDB2 中的 ERP1 远程克隆为 CDB1 中的 PDB6 对应路径:Cre ...

  8. UNICODE下CString转string

    真搞不懂,为毛C++这么多类型转换.. CString m_str(_T("fuck conversion")); char *chr=new char[m_str.GetLeng ...

  9. totensor方法和normalize方法 数值映射和归一化

    totensor方法和normalize方法 数值映射和归一化 待办 ToTensor是指把PIL.Image(RGB) 或者numpy.ndarray(H x W x C) 从0到255的值映射到0 ...

  10. Java爬虫学习(1)之爬取新浪微博博文

    本次学习采用了webmagic框架,完成的是一个简单的小demo package com.mieba.spiader; import us.codecraft.webmagic.Page; impor ...