bzoj2982: combination
借(cao)鉴(xi)自popoqqq大爷的lucas定理的写法
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int mod=10007;
int inv[mod],fac[mod];
int get(int n,int m){
if(n<m) return 0;
if(n<mod&&m<mod) return fac[n]*inv[m]%mod*inv[n-m]%mod;
return get(n/mod,m/mod)*get(n%mod,m%mod)%mod;
}
int main(){
fac[0]=1;
rep(i,1,mod-1) fac[i]=fac[i-1]*i%mod;
inv[0]=1;inv[1]=1;
rep(i,2,mod-1) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
rep(i,1,mod-1) inv[i]=inv[i-1]*inv[i]%mod;
int t=read();
while(t--){
int n=read(),m=read();
printf("%d\n",get(n,m));
}
return 0;
}
2982: combination
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 377 Solved: 240
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
5 1
5 2
7 3
4 2
Sample Output
10
35
6
HINT
Source
bzoj2982: combination的更多相关文章
- 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
1.题意:求 C(n,m) % 10007 ,10007是质数咯 n和m < 2000000000 2.分析:这个东西太大了,显然不能用n!的阶乘预处理的方式搞出来,也不能用递推公式搞出来 于是 ...
- 【题解】 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天,所以他想知道答案 ...
- 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 Lucas定理
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2982 $C(N,M)\% P = C(N\% P,M\% P) * C(N/P,M/P)\ ...
随机推荐
- 单例模式及C++实现
单例模式及C++实现代码 C++中的单例模式http://blog.csdn.net/hackbuteer1/article/details/7460019
- (转)xmpp 环境配置-支持扩展
第一种方法直接拖 1> 拖入文件夹 在网盘链接的xmppFramework文件夹 :http://pan.baidu.com/s/1jGxLa3G 也可以直接去github搜索下载. 2> ...
- POJ 2109
#include<iostream> #include<stdio.h> #include<math.h> using namespace std; int mai ...
- POJ 2021
#include <iostream> #include <string> #include <algorithm> #define MAXN 105 using ...
- 传说中的WCF(12):服务器回调有啥用
你说,服务器端回调有啥用呢?这样问,估计不好回答,是吧.不急,先讨论一个情景. 假设现有服务器端S,客户端A开始连接S并调用相关操作,其中有一个操作,在功能上有些特殊,调用后无法即时回复,因为在服务器 ...
- x86虚拟地址到物理地址的映射学习
这里只谈分页管理的机制,也是目前最重要的内存管理机制. 最初的设计想法: 结构图如下: 页的尺寸是4KB,虚拟地址的前20位用于指定一个物理页,后12位用于访问页内偏移. 页表项的结构: 各个位的含义 ...
- QAQ OI生涯の最后一个月
QAQ 总觉得自己要做点什么 可是并不知道去做些什么 QAQ 先挖一些坑吧,不管怎么样,把这些坑填完估计NOI也就无憾了 1.读完13-16的论文 QAQ 2.做完12-16的POI QAQ 3.做 ...
- JavaWeb笔记——上传文件
jsp上传文件 *<form>标签method属性必须为post,并且添加enctype="multipart/form-data"属性 ------------- ...
- 更新SDK后ADT版本低不支持
在android_sdk_windows/tools/lib下的plugin.prop文件里被变更为 # begin plugin.prop plugin.version=21.1.0 # end p ...
- iOS 深入Objective-C的动态特性
深入Objective-C的动态特性 Objective-C具有相当多的动态特性,基本的,也是经常被提到和用到的有动态类型(Dynamic typing),动态绑定(Dynamic binding)和 ...