借(cao)鉴(xi)自popoqqq大爷的lucas定理的写法

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int mod=10007;
int inv[mod],fac[mod];
int get(int n,int m){
if(n<m) return 0;
if(n<mod&&m<mod) return fac[n]*inv[m]%mod*inv[n-m]%mod;
return get(n/mod,m/mod)*get(n%mod,m%mod)%mod;
}
int main(){
fac[0]=1;
rep(i,1,mod-1) fac[i]=fac[i-1]*i%mod;
inv[0]=1;inv[1]=1;
rep(i,2,mod-1) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
rep(i,1,mod-1) inv[i]=inv[i-1]*inv[i]%mod;
int t=read();
while(t--){
int n=read(),m=read();
printf("%d\n",get(n,m));
}
return 0;
}

  

2982: combination

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 377  Solved: 240
[Submit][Status][Discuss]

Description

LMZn个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样。那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案mod 10007的值。(1<=m<=n<=200,000,000)

Input

  第一行一个整数t,表示有t组数据。(t<=200)
  接下来t行每行两个整数n, m,如题意。

Output

T行,每行一个数,为C(n, m) mod 10007的答案。

Sample Input

4
5 1
5 2
7 3
4 2

Sample Output

5
10
35
6

HINT

 

Source

 

[Submit][Status][Discuss]

bzoj2982: combination的更多相关文章

  1. BZOJ2982: combination Lucas模板

    2982: combination Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 734  Solved: 437[Submit][Status][Di ...

  2. bzoj2982: combination(lucas定理板子)

    2982: combination Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 664  Solved: 397[Submit][Status][Di ...

  3. BZOJ2982——combination

    1.题意:求 C(n,m) % 10007 ,10007是质数咯 n和m < 2000000000 2.分析:这个东西太大了,显然不能用n!的阶乘预处理的方式搞出来,也不能用递推公式搞出来 于是 ...

  4. 【题解】 bzoj2982: combination (Lucas定理)

    题面戳我 Solution 板子题 Code //It is coded by ning_mew on 7.25 #include<bits/stdc++.h> #define LL lo ...

  5. bzoj2982: combination(Lucas定理)

    Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...

  6. BZOJ2982: combination Lucas

    Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...

  7. 2018.09.14 bzoj2982: combination(Lucas定理)

    传送门 貌似就是lucas的板子题啊. 练一练手感觉挺舒服的^_^ 代码: #include<bits/stdc++.h> #define mod 10007 #define ll lon ...

  8. bzoj2982: combination(lucas)

    Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...

  9. [BZOJ2982]combination Lucas定理

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2982 $C(N,M)\% P = C(N\% P,M\% P) * C(N/P,M/P)\ ...

随机推荐

  1. C# 工厂

    /// <summary> /// 创造实例 /// </summary> /// <typeparam name="T">类型</typ ...

  2. java控制反转与依赖注入

    1.简介 依赖注入和控制反转,目的是为了使类与类之间解耦合,提高系统的可扩展性和可维护性,下面通过一个例子来引入这一概念. 2.案例 1)一般情况下的类耦合 Main.java public clas ...

  3. Understanding node.js

    Node.js has generally caused two reactions in people I've introduced it to. Basically people either ...

  4. 【转载】 硬盘主引导记录(MBR)及其结构详解

    硬盘的0柱面.0磁头.1扇区称为主引导扇区,FDISK程序写到该扇区的内容称为主引导记录(MBR).该记录占用512个字节,它用于硬盘启动时将系统控制权交给用户指定的,并在分区表中登记了的某个操作系统 ...

  5. Useful for Android the development engineer from Github

    Original:http://sysmagazine.com/posts/216591/ Many plowing on open space Github, I found assemblage ...

  6. http://www.cnblogs.com/yjmyzz/p/dubbox-demo.html

    http://www.cnblogs.com/yjmyzz/p/dubbox-demo.html

  7. Hadoop InputFormat OutputFormat

    InputFormat有两个抽象方法: getSplits     createRecordReader   InputSplits 将数据按照Split进行切分,一个Split分给一个task执行. ...

  8. Spring学习总结(2)——Spring IOC的前世今生

    前些天,参与了公司内部小组的一次技术交流,主要是针对<IOC与AOP>,本着学而时习之的态度及积极分享的精神,我就结合一个小故事来初浅地剖析一下我眼中的“IOC前世今生”,以方便初学者能更 ...

  9. http://blog.csdn.net/hguisu/article/details/7533759

    http://blog.csdn.net/hguisu/article/details/7533759

  10. WebService另一种轻量级实现—Hessian 学习笔记

    最近和同事聊天,得知他们在使用一种叫做Hessian的WebService实现方式实现远 程方法调用,是轻量级的,不依赖JavaEE容器,同时也是二进制数据格式传输,效率比SOAP的XML方式要高.感 ...