Code:

  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define maxn 1000003
  4. using namespace std;
  5. const ll mod = 10007;
  6. void setIO(string s)
  7. {
  8. string in=s+".in";
  9. freopen(in.c_str(),"r",stdin);
  10. }
  11. struct Comb
  12. {
  13. ll fac[maxn];
  14. ll qpow(ll base,ll k)
  15. {
  16. ll tmp=1;
  17. while(k)
  18. {
  19. if(k&1)tmp=tmp*base%mod;
  20. k>>=1;
  21. base=base*base%mod;
  22. }
  23. return tmp;
  24. }
  25. void init()
  26. {
  27. int i;
  28. fac[1]=fac[0]=1;
  29. for(i=2;i<maxn;++i) fac[i]=(fac[i-1]*i)%mod;
  30. }
  31. ll getinv(ll a)
  32. {
  33. return qpow(a,mod-2);
  34. }
  35. ll C(ll n,ll m)
  36. {
  37. if(m==0) return 1;
  38. if(n<m) return 0;
  39. return (fac[n]*getinv(fac[n-m]*fac[m]))%mod;
  40. }
  41. ll lucas(ll n,ll m)
  42. {
  43. if(m==0) return 1;
  44. return (lucas(n/mod,m/mod)*C(n%mod,m%mod))%mod;
  45. }
  46. }t;
  47. int main()
  48. {
  49. // setIO("input");
  50. int T,n,m;
  51. scanf("%d",&T);
  52. t.init();
  53. while(T--)
  54. {
  55. scanf("%d%d",&n,&m);
  56. if(n<m) swap(n,m);
  57. printf("%lld\n",t.lucas(n,m));
  58. }
  59. return 0;
  60. }

  

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. eclipse下实现热部署,tomcat不重新reload context

    1. 打开server的编辑器 2. 在modules页签内,修改auto load属性为disabled

  2. 测开之路七十一:监控平台之js

    监控平台的js //datetimepicker的初始化函数(主要是对选择时间的下拉框)function init_datetimepicker() { //初始化格式和规则 $('#start'). ...

  3. centos6.5下apollo1.7.1的搭建

    前言:apollo MQ作为消息队列中间件,在需要消息列表的应用程序环境中,需要使用该服务器中间件 1.准备工作 2.搭建 3.测试 1.准备工作 第一步:linux系统中配置好java环境 A.卸载 ...

  4. mysql一主多从配置详情

    https://www.cnblogs.com/zgx/archive/2011/09/13/2174823.html 1.准备好3台虚机,一台master,两台slave且都安装好mysql 2.主 ...

  5. 题解1235. 洪水 (Standard IO)

    Description 一天, 一个画家在森林里写生,突然爆发了山洪,他需要尽快返回住所中,那里是安全的.森林的地图由R行C列组成,空白区域用点“.”表示,洪水的区域用“*”表示,而岩石用“X”表示, ...

  6. [7期]美少妇(msf)和独角兽(unicorn)

    MSF 全称:metasploit-framework    渗透大杀器,黑客工具排名第一(靠前),尤其在内网中.在校期间大学生先跟本校安全部沟通好,一起实验. 得不到校方理解与认可的上SRC或者自己 ...

  7. Git011--分支管理策略

    Git--分支管理策略 一.分支管理策略 通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,G ...

  8. Maven系列学习(二)Maven使用入门

    Maven使用入门 通过上一节的学习,我们已经了解和配置好了Maven,接下来需要编写代码了 1.POM(Project Object Model,项目对象模型) 和Make的Makefile类似,M ...

  9. spring-第八篇之容器中的bean的生命周期

    1.容器中的bean的生命周期 spring容器可以管理singleton作用域的bean的生命周期,包括bean何时被创建.何时初始化完成.何时被销毁.客户端代码不能控制该类型bean的销毁.spr ...

  10. 2014 SummerTrain Beautiful Garden

    There are n trees planted in lxhgww's garden. You can assume that these trees are planted along the ...