题目链接: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求组合数)的更多相关文章

  1. lucas求组合数C(n,k)%p

    Saving Beans http://acm.hdu.edu.cn/showproblem.php?pid=3037 #include<cstdio> typedef __int64 L ...

  2. HDU 5698——瞬间移动——————【逆元求组合数】

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

  3. 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)

    先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...

  4. URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理

    URAL 1994 The Emperor's plan 求组合数 大数用log #include<functional> #include<algorithm> #inclu ...

  5. 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)( ...

  6. 求组合数、求逆元、求阶乘 O(n)

    在O(n)的时间内求组合数.求逆元.求阶乘.·.· #include <iostream> #include <cstdio> #define ll long long ;// ...

  7. HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解

    题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...

  8. 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 ...

  9. 求组合数 C++程序

    一 递归求组合数 设函数为void    comb(int m,int k)为找出从自然数1.2.... .m中任取k个数的所有组合. 分析:当组合的第一个数字选定时,其后的数字是从余下的m-1个数中 ...

随机推荐

  1. MFC之自绘控件

    在描绘MFC界面时,MFC自带的控件样式是绝对不满足界面的需求的. 所以我们就要在MFC自带控件基础上对控件样式进行重绘. 在采用自绘前界面样式 采用自绘后界面样式 是不是自绘控件后看起来正常了很多? ...

  2. 【RF库XML测试】Element Attribute Should Be

    Name:Element Attribute Should BeSource:XML <test library>Arguments:[ source | name | expected ...

  3. shell中判断是否是月末的方法

    判断今天是不是一月的最后一天: 如果$(TZ=IST-32 date +%d)是1就是月末了.

  4. 与MQ通讯的完整JAVA程序

    该程序实现了发送消息与读取消息的功能,见其中的 send***与get***方法.这只适合于测试,因为环境中的程序还需要对此有稍微的更改,在真实的环境中肯定是在while(true){...} 的无限 ...

  5. RabbitMQ之总结

    P:生成者,消息产生者: C:消息消费者: 红:消息队列: java实现 步骤: 创建连接 从连接中创建通道(相当于JDBC中的Statement) 通过channel声明(创建)队列.(如果队列存在 ...

  6. C++ template —— 模板特化(五)

    本篇讲解模板特化-------------------------------------------------------------------------------------------- ...

  7. 开启mysql远程连接访问权限的几种方法

    1.改表法. 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 " ...

  8. css案例 - 评分效果的星星✨外衣

    纳尼?什么星星外衣?好,直接上图比较能说清楚: 仔细看会发现规律:可以根据百分比/分值动态改变高亮星星的个数. 分步骤图: 这种效果,如果遇到一分一个星,没有半星(或者有也可以,直接加一个半星的类名) ...

  9. LeetCode 13 Roman to Integer(罗马数字转为整数)

    题目链接 https://leetcode.com/problems/roman-to-integer/?tab=Description   int toNumber(char ch) { switc ...

  10. sencha touch 隐藏滚动条样式的几种方式

    如图,当滚动条显示时不是那么的好看   可以通过以下几种方式来隐藏滚动条,而又不影响滚动效果 1.通过css隐藏 /* 隐藏x方向滚动条 */ .x-scroll-bar-x.active { wid ...