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模板题的更多相关文章

  1. bzoj 2982 combination——lucas模板

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2982 明明是lucas定理裸题…… 非常需要注意C( )里  if ( n<m ) r ...

  2. 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 ...

  3. BZOJ 2982: combination( lucas )

    lucas裸题. C(m,n) = C(m/p,n/p)*C(m%p,n%p). ----------------------------------------------------------- ...

  4. 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 ...

  5. BZOJ2982: combination Lucas模板

    2982: combination Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 734  Solved: 437[Submit][Status][Di ...

  6. bzoj——2982: combination

    2982: combination Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 611  Solved: 368[Submit][Status][Di ...

  7. BZOJ 2724 蒲公英 | 分块模板题

    题意 给出一个序列,在线询问区间众数.如果众数有多个,输出最小的那个. 题解 这是一道分块模板题. 一个询问的区间的众数,可能是中间"整块"区间的众数,也可能是左右两侧零散的数中的 ...

  8. BZOJ 2982 combination

    lucas定理裸题. #include<iostream> #include<cstdio> #include<cstring> #include<algor ...

  9. BZOJ 1180 / 2843 LCT模板题_双倍经验

    一大早上到机房想先拍一下模板,热热身. 结果....对照着染色敲的 LCT 竟然死活也调不过去(你说我抄都能抄错) 干脆自己重新敲了一遍,10min就敲完了....... 还是要相信自己 Code: ...

随机推荐

  1. joke python

    w # -*- coding: utf-8 -*- import pycurl import re import cStringIO from pypinyin import lazy_pinyin ...

  2. 网路编程之socket与 socketserver、黏包

    socket与socketerver才是我们学习python中网络编程的重中之重在介绍他们两个之前我先介绍一些相关知识 一.socket 概念 咱们现在ois模型中找到socket所承担的角色 soc ...

  3. 九个console命令调试JS

    下面九个console命令,可以帮助我们更方便地调试 常用的console命令,最常用的事console.log() 1 //常用的console命令,其中最常用的console.log() 2 co ...

  4. jmeter之JDBC请求

    jmeter不仅可以测试http请求,也可以执行JDBC请求的测试.本次以mysql为例,介绍JDBC请求如何完成发送 目录 1.环境配置 2.数据库连接配置 3.添加一个JDBC请求 1.环境配置 ...

  5. python判断字符串是否是json格式方法分享

    python判断字符串是否是json格式方法分享 在实际工作中,有时候需要对判断字符串是否为合法的json格式 解决方法使用json.loads,这样更加符合'Pythonic'写法 代码示例:   ...

  6. springboot异步任务、定时任务

    打开浏览器 http://localhost:8080/hello ,连续刷新可以看到不会 等待 3秒时间了,pom.xml controller service 代码如下. -----------S ...

  7. Vue2.0响应式原理以及重写数组方法

    // 重写数组方法 let oldArrayPrototype = Array.prototype; let proto = Object.create(oldArrayPrototype); ['p ...

  8. tmux多终端工具

    在Linux服务器上没有办法像在桌面系统一样开多个终端,所以有时后进行一些操作不是太方便,所以可以使用tmux工具,创建多个终端. 这里仅仅是简单的介绍一下如何创建多个终端和进行多个终端之间切换,tm ...

  9. 巧用css内容生成

    1.      .box:before{content:"生成内容";}在.box内部的内容之前加上生成内容 2.       .box:after{content:"生 ...

  10. go 协程(Goroutine)

    Go 协程是什么? Go 协程是与其他函数或方法一起并发运行的函数或方法.Go 协程可以看作是轻量级线程.与线程相比,创建一个 Go 协程的成本很小.因此在 Go 应用中,常常会看到有数以千计的 Go ...