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. 关于 推广QQ

    有一个项目 需要在用户提交表单之后,关闭页面,微信公众号发送一个模板消息,链接地址为qq推广的链接. 早上在试 先是在电脑端测试都是正常的. 然后开始上传到服务器端测试,发送模板消息之前的动作,都没有 ...

  2. 5期-Metasploitable3专题课程

    metasploitable2基于ubantu的渗透演练环境.Rapid7官方长时间未更新,导致跟不上当前的节奏.metasploitable3出世. metasploitable2配合metaspl ...

  3. Git014--Rebase

    Git--Rebase 本文来自于:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b00 ...

  4. JQ获取当前根目录

    function getRootPath_web() {            //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp  ...

  5. jQuery基础--事件处理

    2. jQuery事件机制 JavaScript中已经学习过了事件,但是jQuery对JavaScript事件进行了封装,增加并扩展了事件处理机制.jQuery不仅提供了更加优雅的事件处理语法,而且极 ...

  6. 炫酷CSS3加载动画

    <!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8&qu ...

  7. 跨域(SpringBoot)

    概念: 在 HTML 中,<a>, <form>, <img>, <script>, <iframe>, <link>等标签以及 ...

  8. hdu1423 最长公共上升子序列

    题目传送门 Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  9. 缓存模块redis

    1.安装 安装 下载 :wget http://download.redis.io/releases/redis-3.2.8.tar.gz 解压:tar xzf redis-3.2.8.tar.gz ...

  10. vue iview分页

    距离上次博客更新已经快一个月了,期间也有想法在空闲的时候更新几篇博文. 燃鹅,最近懒癌作祟,丢掉的东西越来越多,再不遏止的话就真成癌了. 趁着刚看完一篇心灵鸡汤,让打满鸡血的我总结下前段时间用到的iv ...