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: ...
随机推荐
- vue搭建项目之设置代理
前面将项目页面.axios.组件等都准备好了,现在就差设置代理了: 首先在config下新建两个文件,分别叫做dev.uri.js和prod.uri.js,代码为: module.exports = ...
- 16/7/14-MySQL-修改mysql5.6以上版本root密码
版本更新,原来user里的password字段已经变更为authentication_string 版本更新 缘故,好多网上的教程都不适用了,甚至连官网的文档也不是能够顺利操作的. 如果 MySQL ...
- 安全体系建设-OWASP
OWASP Checklist Spiders, Robots and Crawlers IG- Search Engine Discovery/Reconnaissance IG- Identify ...
- mysql 数据库表结构对比语句
判断两个数据库互相不存在的表 select a.TABLE_SCHEMA,a.TABLE_NAME from information_schema.TABLES a where a.TABLE_SCH ...
- nodejs安装失败
原文链接:https://www.cnblogs.com/huiziblog666/p/6274494.html 出现error 2502 和error2503是因为win8的权限问题所导致的,具体说 ...
- Python入门习题3.天天向上
例3.1 一年365天,以第一天的能力值为基数,记为1.0,当好好学习时能力值相比前一天提高1%,当没有学习时能力值相比前一天下降1%.每天努力(dayup)和每天放任(daydown),一年下来的能 ...
- Codeforces - 1088B - Ehab and subtraction - 堆
https://codeforc.es/contest/1088/problem/B 模拟即可. #include<bits/stdc++.h> using namespace std; ...
- python学习第十二天列表的循环,排序,统计操作方法
python列表最重要的列表的循环,任何有序列表离不开循环,列表的循环 for in range等关键词,还有列表排序,正序,倒序,还有列表每个元素的最大,最小,统计元素的个数等. 1,列表的循环 ...
- jxl读取excel浮点数据时,小数点后三位截取问题
今天导入Excel数据时,发现很多浮点数据被自动四舍五入只保留了三位,原来是jxl里对getContents()进行了封装,对数值型数据作了该处理.一般我们会对读取excel的一整套流程作为工具类,那 ...
- mod_jk是Apache服务器的一个可插入模块
mod_jk简称JK,是Apache服务器的一个可插入模块,用以为Apache或IIS服务器提供处理JSP/Servlet的能力. Apache作为一款强大的Web服务器,本身缺乏处理JSP/Serv ...