借(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. 关于JS中的constructor与prototype

    ======================================================================== 在学习JS的面向对象过程中,一直对constructo ...

  2. 结合NGUI做的手机拍照(可自定义相框)

    原地址:http://www.unity蛮牛.com/thread-18220-1-1.html 在次此之前我们先要了解一下下面的我要讲的几个内容: 一.为什么要用NGUI,因为NGUI的可以做屏幕自 ...

  3. C#创建UTF8无BOM文本文件

    In order to omit the byte order mark (BOM), your stream must use a custom instance of UTF8Encoding i ...

  4. 在Delphi中实现动画窗口

    Windows下有一个函数AnimateWindow,在Delphi自带的Win32 API Help中是找不到的.你可以在Delphi的编辑器中输入windows.等待代码向导出来,继续输入Anim ...

  5. GCD的简单封装

    扩展: dispatch_block_t :无参数block,使用起来很简单 下载链接:http://pan.baidu.com/s/1bndN6Yb    ]; }     //定时器 - (voi ...

  6. 40页PPT告诉你真正的"互联网+"

    点这里 40页PPT告诉你真正的"互联网+" 2015-04-06 网站分析公会 超过50万名互联网从业人士关注 互联网运营领域最具影响力自媒体 本文根据和君赵大伟关于互联网思维大 ...

  7. Javascript 正则表达式笔记2

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  8. oracle创建表空间,创建用户(转)

    //创建临时表空间 create temporary tablespace test_temp tempfile 'E:\oracle\product\10.2.0\oradata\testserve ...

  9. 编程实现linux下的shell

    /************************************************************************* > File Name: Kris_shel ...

  10. HDU5597/BestCoder Round #66 (div.2) GTW likes function 打表欧拉函数

    GTW likes function      Memory Limit: 131072/131072 K (Java/Others) 问题描述 现在给出下列两个定义: f(x)=f_{0}(x)=\ ...