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 ...
随机推荐
- Python之Pandas使用教程(转)
https://blog.csdn.net/XiaoYi_Eric/article/details/79506660
- JavaScript如何实现拖放功能
1.在学习ExtJs时,对其拖放功能感到很陌生,然后找了个拖放功能实现. 转载地址 2.拖拽的基本原理就是根据鼠标的移动来移动被拖拽的元素.鼠标的移动也就是x.y坐标的变化:元素的移动就是style. ...
- (1.2)mysql 索引概念
索引的存储分类:mysql目前提供了以下4种索引 [1]B-Tree索引:最常见的索引类型,大部分引擎都支持B树索引 [2]HASH索引:只有Memory引擎支持,使用场景简单 [3]R-Tree索引 ...
- .NET Core 2.0 官方下载地址及中文教程
开发.net core 应用需要安装.NET Core 2.0 SDK http://www.microsoft.com/net/download/core#/sdk 电脑上运行 .net core ...
- word 加载adobe acrobat ,保存word中的清晰图片
1:先安装 adobe 并激活 https://blog.csdn.net/xintingandzhouyang/article/details/82558235 2:打开word,点击 文件&g ...
- git pull报错,error: cannot lock ref导致拉流失败
使用git命令删除相应refs文件,git update-ref -d refs/remotes/XXX,或者手动删除文件 简单粗暴强行git pull,执行git pull -p 原文:https: ...
- win10 + cuda(v9.0) 安装TensorFlow-gpu版
之前在实习公司的电脑上装过TensorFlow-gpu,那时候很快就装好了.但在自己的笔记本上装时,却搞了很久... 一部分原因是因为用校园网下载cuda toolkit 和cudnn ,总是在最后时 ...
- iOS 开发笔记-Storyboard
什么时候用Pust,什么时候用Modal? 一般情况下,是导航控制器点过去的,都使用Pust.如果是相对独立的,则用Modal,比如是导航上面的+添加之类. 关闭一个Modal -(IBAction) ...
- myeclipse自带的数据库查看文件
jdbc:mysql://localhost:3306/videocms?useUnicode=true&characterEncoding=utf8
- 025-du命令查看文件大小
1.查看某个目录下面所有文件占用空间大小并排序.du -sh 目录 2.排序.sort -h