题目链接: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. Jsoup(一)-- HelloWorld

    1.简介 jsoup 是一款Java 的HTML解析器,可直接解析某个URL地址.HTML文本内容.它提供了一套非常省力的API,可通过DOM,CSS以及类似于jQuery的操作方法来取出和操作数据. ...

  2. 一句话shell

    作者:NetSeek1.删除0字节文件find -type f -size 0 -exec rm -rf {} \; 2.查看进程按内存从大到小排列ps -e -o "%C : %p : % ...

  3. 第二篇:Hadoop 在Ubuntu Kylin系统上的搭建[图解]

    前言 本文介绍如何在Ubuntu Kylin操作系统上搭建Hadoop平台. 配置 1. 操作系统: Ubuntu Kylin 14.04 2. 编程语言: JDK 1.8 3. 通信协议: SSH ...

  4. codeforces水题100道 第九题 Codeforces Beta Round #63 (Div. 2) Young Physicist (math)

    题目链接:http://www.codeforces.com/problemset/problem/69/A题意:给你n个三维空间矢量,求这n个矢量的矢量和是否为零.C++代码: #include & ...

  5. 《Lua程序设计》第1章 开始 学习笔记

    1.1 程序块(chunk)每段代码(例如一个源代码文件或在交互模式中输入的一行代码),称为一个程序块.若使用命令行参数-i来启动Lua解释器,那么解释器就会在运行完指定程序块后进入交互模式.dofi ...

  6. Spring系列之访问数据库

    一.概述 Spring的数据访问层是以统一的数据访问异常层体系为核心,结合JDBC API的最佳实践和统一集成各种ORM方案,完成Java平台的数据访问. 二.JDBC API的最佳实践 Spring ...

  7. web_qianduan

    <!DOCTYPE html><html lang="zh"><head><meta charset="UTF-8"& ...

  8. 【Nginx】服务器中HTTP 301跳转到带www的域名的方法

    从nginx的官方文档 documentation, 正确的nginx https 301跳转到带www域名方法的方法如下: HTTP 301跳转到带www域名方法 需要两个server段. serv ...

  9. 高效使用github

    下面两个资料是我在github上面整理出来的repo,不断进行更新,将遇到的有帮助的文章尽量整理到上面,方便初学者也方便回顾学习.如果恰好你也有一些资料文章,欢迎fork - modify - pul ...

  10. Word 2010 插入其他文件的方法

    1. 2.