题目链接:https://www.luogu.org/problemnew/show/P3807

Lucas定理用来求大组合数对一个质数取模的值,不大于10^5用逆元,大于10^5就用Lucas转化成10^5以内,如果不是质数还要用扩展Lucas

Lucas(n,m,p) = C(n%p,m%p)*Lucas(n/p,m/p,p)

 #include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = ;
int n, m, p, T;
long long a[maxn], b[maxn];
long long Lucas(int n, int m, int p)
{
if(n < m) return ;
else if(n < p) return b[n]*a[m]*a[n-m]%p;
else return Lucas(n%p,m%p,p)*Lucas(n/p,m/p,p)%p;
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&p);
a[] = , a[] = , b[] = , b[] = ;
for(int i = ; i <= m+n; i++) b[i] = b[i-]*i%p;
for(int i = ; i <= m+n; i++) a[i] = (p-p/i)*a[p%i]%p;
for(int i = ; i <= m+n; i++) a[i] = a[i-]*a[i]%p;
printf("%lld\n",Lucas(n+m,m,p));
}
return ;
}

【luogu P3807 卢卡斯定理】 模板的更多相关文章

  1. 【数论】卢卡斯定理模板 洛谷P3807

    [数论]卢卡斯定理模板 洛谷P3807 >>>>题目 [题目] https://www.luogu.org/problemnew/show/P3807 [输入格式] 第一行一个 ...

  2. 【luogu P3807】【模板】卢卡斯定理/Lucas 定理(含 Lucas 定理证明)

    [模板]卢卡斯定理/Lucas 定理 题目链接:luogu P3807 题目大意 求 C(n,n+m)%p 的值. p 保证是质数. 思路 Lucas 定理内容 对于非负整数 \(n\),\(m\), ...

  3. Lucas(卢卡斯)定理模板&&例题解析([SHOI2015]超能粒子炮·改)

    Lucas定理 先上结论: 当p为素数: \(\binom{ N }{M} \equiv \binom{ N/p }{M/p}*\binom{ N mod p }{M mod p} (mod p)\) ...

  4. 【Luogu3807】【模板】卢卡斯定理(数论)

    题目描述 给定\(n,m,p(1≤n,m,p≤10^5)\) 求 \(C_{n+m}^m mod p\) 保证\(P\)为\(prime\) \(C\)表示组合数. 一个测试点内包含多组数据. 输入输 ...

  5. hdu3037——卢卡斯定理

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3037 卢卡斯定理模板——大组合数取模 #include<iostream> #include& ...

  6. hdu3037Saving Beans——卢卡斯定理

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3037 卢卡斯定理模板——大组合数的取模 代码如下: #include<iostream> #i ...

  7. 2019西北工业大学程序设计创新实践基地春季选拔赛 D(卢卡斯定理)

    链接:https://ac.nowcoder.com/acm/contest/553/D来源:牛客网 Chino with Equation 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C ...

  8. P3807 【模板】卢卡斯定理

    P3807 [模板]卢卡斯定理 求 \(C_{m + n}^{m} \% p\) ( \(1\le n,m,p\le 10^5\) ) 错误日志: 数组开小(哇啊啊啊洼地hi阿偶我姑父阿贺佛奥UFO爱 ...

  9. 洛谷 P3807 【模板】卢卡斯定理

    P3807 [模板]卢卡斯定理 题目背景 这是一道模板题. 题目描述 给定n,m,p(1\le n,m,p\le 10^51≤n,m,p≤105) 求 C_{n+m}^{m}\ mod\ pCn+mm ...

随机推荐

  1. Coursera 机器学习 第6章(上) Advice for Applying Machine Learning 学习笔记

    这章的内容对于设计分析假设性能有很大的帮助,如果运用的好,将会节省实验者大量时间. Machine Learning System Design6.1 Evaluating a Learning Al ...

  2. vue分页

    1.依赖文件 <link href="/css/index.css" rel="stylesheet" type="text/css" ...

  3. 动作方法中 参数,Json

    一.方法中可以出现的参数类 1.HttpServletRequest 2.HttpServletResponse 3.HttpSession 4.Model 二.返回接收json数据 1. 接收,返回 ...

  4. C#学习笔记13

    1.Task概述:Task是对操作系统线程的抽象,目的是使线程池能高效地管理线程的分配和回收,Task使用的底层线程属于一种共享资源,任务需要互相协作,并及时归还线程,以便用相同的共享资源(线程)满足 ...

  5. PAT 1062 Talent and Virtue

    #include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #i ...

  6. html-框架标签的使用

    <frameset> - rows:按照行进行划分 ** <frameset rows="80,*"> - cols:按照列进行划分 ** <fram ...

  7. HDU 5215 Cycle(dfs判环)

    题意 题目链接 \(T\)组数据,给出\(n\)个点\(m\)条边的无向图,问是否存在一个奇环/偶环 Sol 奇环比较好判断吧,直接判是否是二分图就行了.. 偶环看起来很显然就是如果dfs到一个和他颜 ...

  8. phonegap2.0+在xcode4.5上的搭建

    首先网上很多文章都是phonegap1.X的,可是自2.0后就没有相关的安装文件了,只有官网上写了怎么装 不过官网有时候打不开,可能是首页出了问题 但http://docs.phonegap.com这 ...

  9. DLRS(深度学习应用于推荐系统论文汇总--2017年8月整理)

    Recommender Systems with Deep Learning Alessandro:ADAAlessandro Suglia, Claudio Greco, Cataldo Musto ...

  10. memcached与spring集成

    一.背景 销售CRM(项目A)将负责管理项目信息系统(项目B)的支付与权限 上级要求为避免频繁调用CRM接口,中间放一级缓存,但要做到缓存中保证最新数据 因项目B已使用memcache作缓存,所以决定 ...