1067 - Combinations---LightOj(Lucas求组合数)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1067
模板求C(n,m)%p, Lucas模板;
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h> using namespace std; #define met(a, b) memset(a, b, sizeof(a))
#define N 1000953
#define INF 0x3f3f3f3f
const int MOD = ; typedef long long LL; LL f[N]; LL Pow(LL a, LL b)
{
LL ans = ;
while(b)
{
if(b&)
ans = ans*a%MOD;
b>>=;
a = a*a%MOD;
}
return ans;
} LL C(LL n, LL m)
{
if(m == )return ;
if(m > n)return ;
/*
LL ans = 1;
for(int i=1; i<=m; i++)
{
LL a = (n-m+i);
LL b = i;
ans = ans*(a*Pow(b, MOD-2)%MOD)%MOD;
}这样会超时,所以要预处理阶乘;
*/
///C(n, m) = n!/(m!(n-m)!)%MOD--->n!/m!%MOD * 1/((n-m)!)%MOD;
/// a/b%MOD == a*b^(MOD-2)%MOD;
LL ans = f[n]*Pow(f[m], MOD-)%MOD * *Pow(f[n-m], MOD-) % MOD; return ans;
} void Fact(LL n)
{
f[] = ;
for(int i=; i<=n; i++)
f[i] = f[i-]*i%MOD; } int main()
{
Fact(MOD);
int T, t = ;
LL n, k;
scanf("%d", &T);
while(T--)
{
scanf("%lld %lld", &n, &k);
LL ans = C(n, k);
printf("Case %d: %lld\n", t++, ans);
}
return ;
}
1067 - Combinations---LightOj(Lucas求组合数)的更多相关文章
- lucas求组合数C(n,k)%p
Saving Beans http://acm.hdu.edu.cn/showproblem.php?pid=3037 #include<cstdio> typedef __int64 L ...
- HDU 5698——瞬间移动——————【逆元求组合数】
瞬间移动 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)
先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...
- URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理
URAL 1994 The Emperor's plan 求组合数 大数用log #include<functional> #include<algorithm> #inclu ...
- N!分解质因子p的个数_快速求组合数C(n,m)
int f(int n,int p) { ) ; return f(n/p,p) + n/p; } https://www.xuebuyuan.com/2867209.html 求组合数C(n,m)( ...
- 求组合数、求逆元、求阶乘 O(n)
在O(n)的时间内求组合数.求逆元.求阶乘.·.· #include <iostream> #include <cstdio> #define ll long long ;// ...
- HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解
题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...
- hdu 2519 求组合数
求组合数 如果求C5 3 就是5*4*3/3*2*1 也就是(5/3)*(4/2)*(3/1) Sample Input5 //T3 2 //C3 25 34 43 68 0 Sample Outpu ...
- 求组合数 C++程序
一 递归求组合数 设函数为void comb(int m,int k)为找出从自然数1.2.... .m中任取k个数的所有组合. 分析:当组合的第一个数字选定时,其后的数字是从余下的m-1个数中 ...
随机推荐
- 个人成长|荣获CNVD年度最有价值漏洞奖
本文共750+字,预计阅读2-3分钟. 前几天,很荣幸受主办方邀请,还拿了CNVD的一个“年度最有价值漏洞奖”,说一说,这几天的故事吧. 11月20号,意外收到一个会议邀请,当时还比较诧异,印象中我在 ...
- 如何使用Web Service新建和更新Wiki页面的内容
公司内部有很多部门都创建了Wiki库,来做知识共享.公司是Hosting的SharePoint环境,不能写服务器端代码,要操作Wiki只能通过Web Service来完成,所以,碰到两个情况: 1)W ...
- Nginx 域名重定向
假设 www.old.com 为旧的域名,而 www.new.com 为新的域名,要实现当我们访问 new 的时候自动重定向到 old 域名,配置如下: server { //第一种配置方法 serv ...
- 编译poco-1.7.8
运行build_vs140.cmd,运行之前可以修改一些参数,例如编译64位 buildwin 140 build shared both x64 nosamples notests devenv 修 ...
- Elasticsearch 配置同义词
配置近义词 近义词组件已经是elasticsearch自带的了,所以不需要额外安装插件,但是想要让近义词和IK一起使用,就需要配置自己的分析器了. 首先创建近义词文档 在config目录下 mkdir ...
- 手机端点击复制链接到剪切板(以及PC端)
一直在找如何能点击按钮将一串字符串放到手机的剪切板上,但是可能是因为搜索的关键字不对,一直无果. 向同事请教了一下,给了一个clickboard.js的插件.开始试验的时候,使用手机自带浏览器进行测试 ...
- Jquery 网页转换为图片
/* html2canvas 0.5.0-alpha1 <http://html2canvas.hertzen.com> Copyright (c) 2015 Niklas von Her ...
- IOS设计模式第九篇之备忘录模式
版权声明:原创作品,谢绝转载!否则将追究法律责任. 备忘录模式捕获和具体化对象的内部状态.换句话说,它可以节省你的东西后来,这种外部状态可以恢复在不违反封装; 也就是说,私人数据是私有的. 怎么用备忘 ...
- key是数字的对象集合
整理如下: let data = {3: '影视', 4: '音乐', 5: '广场舞', 6: '游戏', 7: '综艺', 8: '动漫', 9: '翻唱', 10: '生活', 11: '美食' ...
- hdu3507 Print Article[斜率优化dp入门题]
Print Article Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)To ...