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. 【查阅】mysql系统视图查看

    [1]查看表大小 SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', table_rows AS 'Number of Rows', ...

  2. Sql Server索引的原理与应用

    SqlServer索引的原理与应用 转自:http://www.cnblogs.com/knowledgesea/p/3672099.html   索引的概念 索引的用途:我们对数据查询及处理速度已成 ...

  3. android 本地字符串存取

    存 // data 指定的文件名 SharedPreferences.Editor editor = getSharedPreferences("data",MODE_PRIVAT ...

  4. [py][mx]django-解决注册用户已存在,激活链接判断

    注册时候,如果用户已存在,则提示错误 激活用户时候,如果激活链接失效,则提示用户. class RegisterView(View): def get(self, request): register ...

  5. CentOS7更改Docker默认镜像和容器存储位置

    图片出处:https://bobcares.com/wp-content/uploads/docker-change-directory.jpg 一.Why? 通常,当你开始使用docker时,我们并 ...

  6. CentOS.56安装Redis监控工具RedisLive

    RedisLive是一款开源的基于WEB的reids的监控工具,以WEB的形式展现出redis中的key的情况,实例数据等信息! RedisLive在github上的地址:https://github ...

  7. java判断包含contains方法的使用

    java中contains方法是判断是否存在包含关系,比如说a =[1,2,3,4], b=1那么a就包含b contains返回的是布尔类型true 和false,包含的话就返回true,不包含的话 ...

  8. Android adb.exe程序启动不起来处理方法

    经常遇到 Please ensure that adb is correctly located at 'D:\java\sdk\platform-tools\adb.exe' and can be ...

  9. Integer类之equals与hashCode

    一.源码. 1.equals源码.可以看出,比较的是两者的类型相同且内容相同.即是否有相等的int类型的value值. ######################################## ...

  10. Object之总结(一)

    一.Object类中一共有12个方法.一个私有方法,两个保护方法,9个公共方法.另外还有一个静态代码块. 1.registerNatives方法.私有静态本地无参数无返回值. 2.finalize方法 ...