BZOJ2982: combination Lucas
Description
Input
Output
Sample Input
5 1
5 2
7 3
4 2
Sample Output
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的更多相关文章
- BZOJ2982: combination Lucas模板
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 734 Solved: 437[Submit][Status][Di ...
- bzoj2982: combination(lucas定理板子)
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 664 Solved: 397[Submit][Status][Di ...
- [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)\ ...
- 【BZOJ2982】combination Lucas定理
[BZOJ2982]combination Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然, ...
- 【题解】 bzoj2982: combination (Lucas定理)
题面戳我 Solution 板子题 Code //It is coded by ning_mew on 7.25 #include<bits/stdc++.h> #define LL lo ...
- bzoj2982: combination(Lucas定理)
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...
- 2018.09.14 bzoj2982: combination(Lucas定理)
传送门 貌似就是lucas的板子题啊. 练一练手感觉挺舒服的^_^ 代码: #include<bits/stdc++.h> #define mod 10007 #define ll lon ...
- bzoj2982: combination(lucas)
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...
- bzoj2982: combination
借(cao)鉴(xi)自popoqqq大爷的lucas定理的写法 #include<cstdio> #include<cstring> #include<cctype&g ...
随机推荐
- div+css网页标准布局实例教程(一)
今天学习<十天学会web标准(div+css)>的最后一个章节,本章节把前面学习的零碎内容串联起来,组织成一个网站,将根据本人这些年来的从业经验,从建立站点到一个完整的div+css网页的 ...
- 你可能用得到的9段CSS代码
一.opacity兼容 .transparent { filter: alpha(opacity=50);/* internet explorer */ -khtml-opacity: 0 ...
- Java bytesToHexString 解析
一.代码 /** * Convert byte[] to hex string * * @param src byte[] data * @return hex string */ public st ...
- Hibernate错误
1.Field 'id' doesn't have a default value 原来是我的数据设计的时候,把主键的类型定义为int的,原本想是用自增的方式来的,可是由于自己的粗心,写sql语句的时 ...
- mysql 数据操作 单表查询 目录
mysql 数据操作 单表查询 mysql 数据操作 单表查询 简单查询 避免重复DISTINCT mysql 数据操作 单表查询 通过四则运算查询 mysql 数据操作 单表查询 concat()函 ...
- 协作工具 discord 和 slack
discord: https://discordapp.com/ slack: www.slack.com
- POJ2983 Is the Information Reliable?
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=267#problem/B B - ...
- How many Fibs?(poj 2413)大数斐波那契
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/C Description Recall the defi ...
- [LeetCode] 122. Best Time to Buy and Sell Stock II_Easy tag: Dynamic Programming
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] 190. Reverse Bits_Easy tag: Bit Manipulation
Reverse bits of a given 32 bits unsigned integer. Example: Input: 43261596 Output: 964176192 Explana ...