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

Solution

Lucas板子

#include <bits/stdc++.h>

using namespace std ;

const int mod =  ;

int t , n , m ;
int fac[ mod + ] , ifac[ mod + ] ; int power( int a , int b ) {
int ans = , base = a ;
while( b ) {
if( b & ) ans = ans * base % mod ;
base = base * base % mod ;
b >>= ;
}
return ans ;
} int lucas( int a , int b ) {
if( a > b ) return ;
if( b <= mod ) return fac[ b ] % mod * ifac[ a ] % mod * ifac[ b - a ] % mod ;
return lucas( a % mod , b % mod ) % mod * lucas( a / mod , b / mod ) % mod ;
} int main() {
scanf( "%d" , &t ) ;
fac[ ] = ;
for( int i = ; i <= mod ; i ++ ) fac[ i ] = fac[ i - ] * i % mod ;
for( int i = ; i <= mod ; i ++ ) ifac[ i ] = power( fac[ i ] , mod - ) % mod ;
while( t -- ) {
scanf( "%d%d" , &n , &m ) ;
printf( "%d\n" , lucas( m , n ) ) ;
}
return ;
}

BZOJ2982: combination Lucas的更多相关文章

  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 Lucas定理

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

  4. 【BZOJ2982】combination Lucas定理

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

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

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

  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

    借(cao)鉴(xi)自popoqqq大爷的lucas定理的写法 #include<cstdio> #include<cstring> #include<cctype&g ...

随机推荐

  1. javaScript高级教程(四) 复制对象

    //返回新对象,双方互不影响 function clone(obj){ //alert('clone'); if(typeof(obj) != 'object') return obj; if(obj ...

  2. mysql 内置功能 存储过程 创建无参存储过程

    操作哪个数据库,就把存储过程建到那个数据库 例如 现在use db2; 应该把存储过程 建立到db2数据库里 创建无参存储过程 delimiter // # 设置mysql结束符合为// create ...

  3. python的时间差计算

    import time start = time.clock() #当中是你的程序 elapsed = (time.clock() - start) print("Time used:&qu ...

  4. 实习培训——Servlet(7)

    实习培训——Servlet(7) 1  Servlet 异常处理 当一个 Servlet 抛出一个异常时,Web 容器在使用了 exception-type 元素的 web.xml 中搜索与抛出异常类 ...

  5. String.getBytes()未设置字符集导致打印的pdf乱码

    如果不设置字符集会选择系统字符集,系统也没设置,会选iso-8859-1 导致汉字乱码,成为?

  6. 手工利用Chrome浏览器“Javascript控制台”

    1.打开Chrome浏览器,输入网址:http://forum.csdn.net/SList/HTMLCSS/ 2.按下“Ctrl+Shift+J”打开“Javascript控制台”工具 3.动态引用 ...

  7. [LeetCode] 252. Meeting Rooms_Easy tag: Sort

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  8. smali注入常用代码

    注入代码需要注意寄存器个数.1.插入log信息 const-string v2,"SN" invoke-static {v2,v0}, Landroid/util/Log;-> ...

  9. Canvas标签基础

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

  10. Object-C-NSFileHandle

    NSFileHandle 类中得到方法可以很方便的对文件数据进行读写.追加,以及偏移量的操作. NSFileHandle 基本步骤: 1.打开文件,获取一个NSFileHandle 对象 2.对打开N ...