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: ...
随机推荐
- quick bi dashboard 控件样式控制。
控件样式控制 1 想要的效果图 2 查询样式里面进行设置
- Jmeter接口测试报告模板优化
优化后在接口报告的接口信息中,直接展示url,method,结果和响应时间,详情中展示请求和响应数据.具体如下: 模板文件 jmeter-results-detail-report_21.xsl: & ...
- httpclient模拟服务器请求
// 创建默认的httpClient实例. CloseableHttpClient httpclient = HttpClients.createDefault(); // 创建httppost Ht ...
- Spring cloud 注册服务小结
服务注册中心:Eureka.Zookeeper.Cousul.Nacos 使用RestTemplate.openFeign做服务调用,底层使用的是Ribbon. Ribbon做了负载均衡,也可以做一个 ...
- Dedecms织梦后台登陆验证码不显示几种解决方法
Dedecms织梦后台登陆验证码不显示几种解决方法,服务器所造成的验证码不显示问题看这里: 方法一:查看服务器的php版本是否与程序版本兼容(织梦程序PHP版本查看方法:打开www.96net.com ...
- mintUI修改toast样式的问题解决办法
在公共样式中加入 /*修改mintUI 弹窗样式大小*/ .noticeErrorToast{ transform: scale(2) !important; margin-left:-.6rem ! ...
- 双指针---有序数组的TWO SUM
双指针思想,主要用于遍历数组,两个指针指向不同的元素,从而协同完成任务. 有序数组的 Two Sum Leetcode :167. Two Sum II - Input array is sort ...
- git 命令图解
git 命令图解 初始化版本库 git config user.name "lsgx" git config user.email "lsgxthink@163.co ...
- Address already in use : connect
Address already in use : connect 错误以及处理 项目中有过手写并发测试,在长时间的并发测试(超过20秒,美妙超过2000)的情况下出现了以上错误 处理方法如下(抄的) ...
- 基于mesos 安装 jenkins
mesos master 机子上安装 jenkins git clone https://github.com/jenkinsci/mesos-plugin.git && cd me ...