【题解】 bzoj2982: combination (Lucas定理)
Solution
- 板子题
Code
//It is coded by ning_mew on 7.25
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const LL MOD=10007;
int T;
LL A[MOD],B[MOD],n,m;
void pre(){
A[0]=B[0]=A[1]=B[1]=1;
for(int i=2;i<MOD;i++)B[i]=-(MOD/i)*B[MOD%i]%MOD;
for(int i=2;i<MOD;i++)A[i]=i*A[i-1]%MOD,B[i]=B[i]*B[i-1]%MOD;
return;
}
LL C(LL n,LL m){
if(m>n)return 0;
return A[n]*B[n-m]%MOD*B[m]%MOD;
}
LL Lucas(LL n,LL m){
if(m==0)return 1;
return Lucas(n/MOD,m/MOD)*C(n%MOD,m%MOD)%MOD;
}
int main(){
pre();
scanf("%d",&T);
for(int i=1;i<=T;i++){
scanf("%lld%lld",&n,&m);
printf("%lld\n",(Lucas(n,m)%MOD+MOD)%MOD);
}return 0;
}
博主蒟蒻,随意转载。但必须附上原文链接:http://www.cnblogs.com/Ning-Mew/,否则你会场场比赛暴0!!!
【题解】 bzoj2982: combination (Lucas定理)的更多相关文章
- 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能够持续多少个这样的夜晚呢?当然, ...
- ZOJ 3557 & BZOJ 2982 combination[Lucas定理]
How Many Sets II Time Limit: 2 Seconds Memory Limit: 65536 KB Given a set S = {1, 2, ..., n}, n ...
- BZOJ2982: combination Lucas模板
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 734 Solved: 437[Submit][Status][Di ...
- bzoj2982 combination——卢卡斯定理
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2982 卢卡斯定理裸题: 原准备1A来着,结果输出忘了加回车! 预处理阶乘或者现求都可以,感觉 ...
- [NOIP模拟测试7]visit 题解(组合数学+CRT+Lucas定理)
Orz 因为有T的限制,所以不难搞出来一个$O(T^3)$的暴力dp 但我没试 据说有30分? 正解的话显然是组合数学啦 首先$n,m$可能为负,但这并没有影响, 我们可以都把它搞成正的 即都看作向右 ...
- BZOJ2982: combination Lucas
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...
- BZOJ 2982 combination Lucas定理
题目大意:发上来就过不了审核了--总之大意就是求C(n,m) mod 10007 m,n∈[1,2*10^8] 卢卡斯定理:C(n,m)=C(n%p,m%p)*C(n/p,m/p) mod p 要求p ...
- Lucas定理模板【bzoj2982】【combination】
(上不了p站我要死了,侵权度娘背锅) Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ ...
随机推荐
- DelegatingFilterProxy作用浅析
<filter> <filter-name>secondDomainFilter</filter-name> <filter-class>org.spr ...
- Eclipse中Git的使用以及IDEA中Git的使用
一.Eclipse中Git解决冲突步骤: 1.进行文件对比,将所有的文件添加到序列. 2.commit文件到本地仓库. 3.pull将远程仓库的代码更新到本地,若有冲突则会所有的文件显示冲突状态(真正 ...
- 环同态p64推论
1.为什么属于f(x)∈f(I),那么 2.为什么x属于ker,那么f(x)属于f(I)?
- pip国内镜像
[国内镜像] 中国科学技术大学 : https://pypi.mirrors.ustc.edu.cn/simple 清华:https://pypi.tuna.tsinghua.edu.cn/simpl ...
- html总结:float实现span和input输入框同行
例: <input type="text" name="ytdwname" value="<%=user.getYtdwname() %& ...
- vue双向数据绑定的简单实现
vue双向数据绑定的简单实现 参考教程:链接 <!DOCTYPE html> <html lang="en"> <head> <meta ...
- MySQL根据某个字段查询重复的数据
select count(*) '个数',mobile '手机号',`name` '用户名' from users group by mobile having(count(*) > 1); = ...
- SQLServer数据库分页
以 项目表 PM_Project 为例. PM_Project 全部内容如下(共6条数据): 一.Top – Not In - Top 方式分页 直接的,原始的,不采用函数,纯手动挡. 分步探索过 ...
- springboot注解@SpringBootApplication分析
@SpringBootApplication注解用在Spring Boot的入口类上面,是Spring Boot提供的应用启动相关的注解. 直接上注解的源码: @Target(ElementType. ...
- bootstrap modal垂直居中(简单封装)
1.使用modal 弹出事件方法: 未封装前: <!DOCTYPE html> <html lang="en"> <head> <meta ...