【luogu P3807 卢卡斯定理】 模板
题目链接: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 卢卡斯定理】 模板的更多相关文章
- 【数论】卢卡斯定理模板 洛谷P3807
[数论]卢卡斯定理模板 洛谷P3807 >>>>题目 [题目] https://www.luogu.org/problemnew/show/P3807 [输入格式] 第一行一个 ...
- 【luogu P3807】【模板】卢卡斯定理/Lucas 定理(含 Lucas 定理证明)
[模板]卢卡斯定理/Lucas 定理 题目链接:luogu P3807 题目大意 求 C(n,n+m)%p 的值. p 保证是质数. 思路 Lucas 定理内容 对于非负整数 \(n\),\(m\), ...
- Lucas(卢卡斯)定理模板&&例题解析([SHOI2015]超能粒子炮·改)
Lucas定理 先上结论: 当p为素数: \(\binom{ N }{M} \equiv \binom{ N/p }{M/p}*\binom{ N mod p }{M mod p} (mod p)\) ...
- 【Luogu3807】【模板】卢卡斯定理(数论)
题目描述 给定\(n,m,p(1≤n,m,p≤10^5)\) 求 \(C_{n+m}^m mod p\) 保证\(P\)为\(prime\) \(C\)表示组合数. 一个测试点内包含多组数据. 输入输 ...
- hdu3037——卢卡斯定理
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3037 卢卡斯定理模板——大组合数取模 #include<iostream> #include& ...
- hdu3037Saving Beans——卢卡斯定理
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3037 卢卡斯定理模板——大组合数的取模 代码如下: #include<iostream> #i ...
- 2019西北工业大学程序设计创新实践基地春季选拔赛 D(卢卡斯定理)
链接:https://ac.nowcoder.com/acm/contest/553/D来源:牛客网 Chino with Equation 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C ...
- P3807 【模板】卢卡斯定理
P3807 [模板]卢卡斯定理 求 \(C_{m + n}^{m} \% p\) ( \(1\le n,m,p\le 10^5\) ) 错误日志: 数组开小(哇啊啊啊洼地hi阿偶我姑父阿贺佛奥UFO爱 ...
- 洛谷 P3807 【模板】卢卡斯定理
P3807 [模板]卢卡斯定理 题目背景 这是一道模板题. 题目描述 给定n,m,p(1\le n,m,p\le 10^51≤n,m,p≤105) 求 C_{n+m}^{m}\ mod\ pCn+mm ...
随机推荐
- opensuse install oracle 11gR2 Error in invoking target 'agent nmhs' of makefile '../ins_emagent.mk'
转自 http://blog.csdn.net/ly5156/article/details/6647563 遭遇Error in invoking target 'agent nmhs' of ma ...
- ife task0001页面实现细节问题总结
好久没写css了,突然对重构页面陌生了许多.不过也没什么,前面几个月一直扩充知识面,偏重了理论技术学习,结果还不算遗憾.昨天重拾css,针对问题做点总结: 一.语义化方面 1.HTML5新标签使用 标 ...
- ssh免密码登录快速配置方法
环境需求: 两台Linux主机 A (192.168.3.101)和 B(192.168.3.102),如何使用主机 A 免密码登录 主机B ? 配置步骤: 首页登录主机 A ,在主机A上生成自己 ...
- [转]Setting the NLog database connection string in the ASP.NET Core appsettings.json
本文转自:https://damienbod.com/2016/09/22/setting-the-nlog-database-connection-string-in-the-asp-net-cor ...
- IIS7部署网站出现500.19错误(权限不足)的解决方案
错误摘要 HTTP 错误 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效. 详细错误信息 模块 IIS Web Core 通知 未知 处理 ...
- EF 取出demical数据,但需要去点小数,排序
try { BasePaperWeightDAL.Get(o => o.IsDeleted == false && o.IsEnabled == true).OrderByDes ...
- 用单例模式解决临界区(CRITICAL_SECTION)的使用问题
一.前言 最近,在项目中涉及到多线程访问临界资源的问题.为了保护临界资源,可以是使用互斥量或者是使用临界区.由于,我不需要在多进程中同步,又为了效率的考量,所以选择了使用临界区的方式.但是,在使用临界 ...
- springboot 整合kafka
本文介绍如何在springboot项目中集成kafka收发message. 1.先解决依赖 springboot相关的依赖我们就不提了,和kafka相关的只依赖一个spring-kafka集成包 &l ...
- Disruptor之粗糙认识
一 概述 1.Disruptor Disruptor是一个高性能的异步处理框架,一个“生产者-消费者”模型. 2.RingBuffer RingBuffer是一种环形数据结构,包含一个指向下一个槽点的 ...
- 初入门 HTML
---恢复内容开始--- 1.h标签(标题标签) h1~h62.br标签(换行标签) <br/>3.hr标签(水平线标签) <hr/>4.strong(加粗) em(倾斜)5. ...