[bzoj2982]combination
来源:互联网 发布:淘宝统计消费 编辑:程序博客网 时间:2024/05/21 11:32
Description
LMZ有n个不同的基友,他每天晚上要选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
题解
这道题其实是Lucas定理裸题的啦~~
其实也是很水的啦~~
其实Lucas定理本身就很水的啦~~
Lucas定理及证明过程点这里
代码
#include <cstdio>using namespace std;#define md 10007long long ni[10010],jsi[10010],js[10010];long long t,n,m,i;//快速幂long long quickpow(long long a,long long b,long long m){ long long ans=1; while (b!=0) { if (b%2==1) { ans=ans*a%m; b--; } a=a*a%m; b=b/2; } return ans;}//数据范围较小的组合数long long yes(long long n,long long m){ if (n<m) { return 0; } if (m>n-m) { m=n-m; } long long s1=1,s2=1; long long i; for (i=1;i<=m;i++) { s1=s1*(n-i+1)%md; s2=s2*i%md; } return s1*quickpow(s2,md-2,md)%md;}//Lucas定理long long lucas(long long n,long long m){ if (m==0) { return 1; } return (lucas(n/md,m/md)*yes(n%md,m%md)%md);}int main(){ scanf("%lld",&t); for (i=1;i<=t;i++) { scanf("%lld%lld",&n,&m); printf("%lld\n",lucas(n,m)); } return 0;}
阅读全文
1 0
- 【bzoj2982】combination
- BZOJ2982: combination
- [bzoj2982]combination
- BZOJ2982 combination
- bzoj2982 combination
- 【bzoj2982】 combination LUCAS定理
- 【bzoj2982】【combination】【Lucas定理】
- BZOJ2982——combination
- 【lucas定理】BZOJ2982 combination
- BZOJ2982: combination(Lucas定理)
- Lucas定理模板【bzoj2982】【combination】
- bzoj2982: combination 组合数 卢卡斯定理
- [BZOJ2982]combination(组合数学lucas定理)
- 组合数学lucas定理 BZOJ2982 combination
- [bzoj2982]combination(组合数学lucas定理)
- bzoj2982 combination【Lacus定理+线性求逆元】
- bzoj2982 -- Lucas定理
- combination
- 字符编码问题
- 冒泡排序-js
- eclipse创建tomcat server 出现 Cannot create a server using the selected type
- Eclipse中添加Maven插件
- Error:Execution failed for task':app:externalNativeBuildCleanDebug'
- [bzoj2982]combination
- 上线调试和下线调试
- 深入分析MySQL ERROR 1045 (28000)
- 微信小程序 Node.js (基础八) exports模块系统
- 正则表达式
- python 笔记(刷题常用函数)
- Java编程思想之一切都是对象
- 3.4 Git Branching
- [bzoj1711][Usaco2007 Open]Dining吃饭 最大流