BZOJ 2982: combination Lucas模板题
Code:
- #include<bits/stdc++.h>
- #define ll long long
- #define maxn 1000003
- using namespace std;
- const ll mod = 10007;
- void setIO(string s)
- {
- string in=s+".in";
- freopen(in.c_str(),"r",stdin);
- }
- struct Comb
- {
- ll fac[maxn];
- ll qpow(ll base,ll k)
- {
- ll tmp=1;
- while(k)
- {
- if(k&1)tmp=tmp*base%mod;
- k>>=1;
- base=base*base%mod;
- }
- return tmp;
- }
- void init()
- {
- int i;
- fac[1]=fac[0]=1;
- for(i=2;i<maxn;++i) fac[i]=(fac[i-1]*i)%mod;
- }
- ll getinv(ll a)
- {
- return qpow(a,mod-2);
- }
- ll C(ll n,ll m)
- {
- if(m==0) return 1;
- if(n<m) return 0;
- return (fac[n]*getinv(fac[n-m]*fac[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;
- }
- }t;
- int main()
- {
- // setIO("input");
- int T,n,m;
- scanf("%d",&T);
- t.init();
- while(T--)
- {
- scanf("%d%d",&n,&m);
- if(n<m) swap(n,m);
- printf("%lld\n",t.lucas(n,m));
- }
- return 0;
- }
BZOJ 2982: combination Lucas模板题的更多相关文章
- bzoj 2982 combination——lucas模板
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2982 明明是lucas定理裸题…… 非常需要注意C( )里 if ( n<m ) r ...
- 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 ...
- BZOJ 2982: combination( lucas )
lucas裸题. C(m,n) = C(m/p,n/p)*C(m%p,n%p). ----------------------------------------------------------- ...
- 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 ...
- BZOJ2982: combination Lucas模板
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 734 Solved: 437[Submit][Status][Di ...
- bzoj——2982: combination
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 611 Solved: 368[Submit][Status][Di ...
- BZOJ 2724 蒲公英 | 分块模板题
题意 给出一个序列,在线询问区间众数.如果众数有多个,输出最小的那个. 题解 这是一道分块模板题. 一个询问的区间的众数,可能是中间"整块"区间的众数,也可能是左右两侧零散的数中的 ...
- BZOJ 2982 combination
lucas定理裸题. #include<iostream> #include<cstdio> #include<cstring> #include<algor ...
- BZOJ 1180 / 2843 LCT模板题_双倍经验
一大早上到机房想先拍一下模板,热热身. 结果....对照着染色敲的 LCT 竟然死活也调不过去(你说我抄都能抄错) 干脆自己重新敲了一遍,10min就敲完了....... 还是要相信自己 Code: ...
随机推荐
- eclipse下实现热部署,tomcat不重新reload context
1. 打开server的编辑器 2. 在modules页签内,修改auto load属性为disabled
- 测开之路七十一:监控平台之js
监控平台的js //datetimepicker的初始化函数(主要是对选择时间的下拉框)function init_datetimepicker() { //初始化格式和规则 $('#start'). ...
- centos6.5下apollo1.7.1的搭建
前言:apollo MQ作为消息队列中间件,在需要消息列表的应用程序环境中,需要使用该服务器中间件 1.准备工作 2.搭建 3.测试 1.准备工作 第一步:linux系统中配置好java环境 A.卸载 ...
- mysql一主多从配置详情
https://www.cnblogs.com/zgx/archive/2011/09/13/2174823.html 1.准备好3台虚机,一台master,两台slave且都安装好mysql 2.主 ...
- 题解1235. 洪水 (Standard IO)
Description 一天, 一个画家在森林里写生,突然爆发了山洪,他需要尽快返回住所中,那里是安全的.森林的地图由R行C列组成,空白区域用点“.”表示,洪水的区域用“*”表示,而岩石用“X”表示, ...
- [7期]美少妇(msf)和独角兽(unicorn)
MSF 全称:metasploit-framework 渗透大杀器,黑客工具排名第一(靠前),尤其在内网中.在校期间大学生先跟本校安全部沟通好,一起实验. 得不到校方理解与认可的上SRC或者自己 ...
- Git011--分支管理策略
Git--分支管理策略 一.分支管理策略 通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,G ...
- Maven系列学习(二)Maven使用入门
Maven使用入门 通过上一节的学习,我们已经了解和配置好了Maven,接下来需要编写代码了 1.POM(Project Object Model,项目对象模型) 和Make的Makefile类似,M ...
- spring-第八篇之容器中的bean的生命周期
1.容器中的bean的生命周期 spring容器可以管理singleton作用域的bean的生命周期,包括bean何时被创建.何时初始化完成.何时被销毁.客户端代码不能控制该类型bean的销毁.spr ...
- 2014 SummerTrain Beautiful Garden
There are n trees planted in lxhgww's garden. You can assume that these trees are planted along the ...