1. /*
  2. cf369E. ZS and The Birthday Paradox
  3. http://codeforces.com/contest/711/problem/E
  4. 抽屉原理+快速幂+逆元+勒让德定理+费马小定理+欧拉定理+数论
  5. 题解:https://amoshyc.github.io/ojsolution-build/cf/cf369/pe.html
  6.  
  7. 坑点:
  8. 1、long long 类型的常量一定要加LL,否则1<<n只在int范围内
  9. 2、带模的题目,最后一定要判断是否答案为负,答案为负数要加mod
  10. */
  11. #include <cstdio>
  12. #include <algorithm>
  13. using namespace std;
  14. const int mod=;
  15. long long n,k;
  16. long long Legendre(long long n,long long p)//勒让德定理:O(logn) 算出n!中有多少个p
  17. {
  18. long long ans=;
  19. while(n>)
  20. {
  21. ans+=n/p;
  22. n/=p;
  23. }
  24. return ans;
  25. }
  26. long long pow(long long base,long long n)
  27. {
  28. long long ans=;
  29. base=base%mod;//先取模防止爆long long
  30. while(n>)
  31. {
  32. if(n&)
  33. ans=(ans*base)%mod;
  34. base=(base*base)%mod;
  35. n>>=;
  36. }
  37. return ans;
  38. }
  39. int main()
  40. {
  41. //freopen("cf711E.in","r",stdin);
  42. scanf("%I64d%I64d",&n,&k);
  43. if(n<= && k>(1LL<<n))//抽屉原理
  44. {
  45. printf("1 1\n");
  46. return ;
  47. }
  48. long long gcd=Legendre(k-,);
  49. long long p=,q;//p/q;
  50. q=((n%(mod-))*((k-)%(mod-))-gcd%(mod-))%(mod-)+mod-;//欧拉函数降幂
  51. //q=(n%(mod-1))*((k-1)%(mod-1))+mod-1-gcd; this is a wrong way!!!!!!
  52. q=pow(,q)%mod;//q=2^( n(k-1)-gcd ) <=> 2^((n(k-1)-gcd)%phi(mod)+phi(mod) );
  53. if(k->=mod)//抽屉原理得出在分子中必定存在一个%mod=0,标程大坑,不能直接输出1 1,即此处不约分。
  54. p=;
  55. else
  56. {
  57. long long val=pow(,n);
  58. for(long long i=;i<=k-;i++)
  59. {
  60. p=(p*((val-i))%mod)%mod;
  61. }
  62. if(gcd)
  63. {
  64. p=(p*pow(pow(,gcd),mod-))%mod;
  65. //p=(p+mod)/pow(2,gcd);
  66. }
  67. }
  68. p=q-p;
  69. if(p<)//判断是否为负
  70. p+=mod;
  71. printf("%I64d %I64d\n",p,q);
  72. return ;
  73. }

CF369E. ZS and The Birthday Paradox的更多相关文章

  1. codeforces 711E E. ZS and The Birthday Paradox(数学+概率)

    题目链接: E. ZS and The Birthday Paradox. time limit per test 2 seconds memory limit per test 256 megaby ...

  2. ZS and The Birthday Paradox

    ZS and The Birthday Paradox 题目链接:http://codeforces.com/contest/711/problem/E 数学题(Legendre's formula) ...

  3. Codeforces 711E ZS and The Birthday Paradox 数学

    ZS and The Birthday Paradox 感觉里面有好多技巧.. #include<bits/stdc++.h> #define LL long long #define f ...

  4. Codeforces Round #369 (Div. 2) E. ZS and The Birthday Paradox 数学

    E. ZS and The Birthday Paradox 题目连接: http://www.codeforces.com/contest/711/problem/E Description ZS ...

  5. 【Codeforces711E】ZS and The Birthday Paradox [数论]

    ZS and The Birthday Paradox Time Limit: 20 Sec  Memory Limit: 512 MB Description Input Output Sample ...

  6. Codeforces 711E ZS and The Birthday Paradox

    传送门 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output st ...

  7. cf711E ZS and The Birthday Paradox

    ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that g ...

  8. 【28.57%】【codeforces 711E】ZS and The Birthday Paradox

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. codeforces 711E. ZS and The Birthday Paradox 概率

    已知一年365天找23个人有2个人在同一天生日的概率 > 50% 给出n,k ,表示现在一年有2^n天,找k个人,有2个人在同一天生日的概率,求出来的概率是a/b形式,化到最简形式,由于a,b可 ...

随机推荐

  1. 准备开源用javascript写Tomcat下的WebApp的项目

    原创文章,转载请注明. 这个想法由来已久.用javascript编写Tomcat下的WebApp.现现在也有alpha版本号的实现. 这种话,前端程序猿就能够像用Node.js那样,用javascri ...

  2. SQL Server数据库 bcp导出备份文件应用

    /**  * 授权  */ EXEC sp_configure 'show advanced options',1; go reconfigure; go exec sp_configure 'xp_ ...

  3. CNN中的局部连接(Sparse Connectivity)和权值共享

    局部连接与权值共享 下图是一个很经典的图示,左边是全连接,右边是局部连接. 对于一个1000 × 1000的输入图像而言,如果下一个隐藏层的神经元数目为10^6个,采用全连接则有1000 × 1000 ...

  4. [HTML&CSS] 条件注释判断浏览器

    <!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--><!--[if IE]> 所有的IE可识别 <![e ...

  5. 对JVM还有什么不懂的?一文章带你深入浅出JVM!

    本文跟大家聊聊JVM的内部结构,从组件中的多线程处理,JVM系统线程,局部变量数组等方面进行解析 JVM JVM = 类加载器(classloader) + 执行引擎(execution engine ...

  6. History of the browser user-agent string--转

    https://webaim.org/blog/user-agent-string-history/ In the beginning there was NCSA Mosaic, and Mosai ...

  7. 通过阅读《React 进阶之路》之学习笔记

    第一章: React 通过引入虚拟DOM.状态.单向数据流等设计理念,形成以组件为核心,用组件搭建UI的开发模式.

  8. html中map标签和area标签的应用

    map标签的用途:是与img标签绑定使用的,常被用来赋予给客户端图像某处区域特殊的含义,点击该区域可跳转到新的文档. 因为map标签是与img标签绑定使用的,所以我们需要给map标签添加ID和name ...

  9. fabric.js 翻转,复制粘贴,隐藏, 删除,历史记录,撤销, 剪切, 图层,组合打散,锁定等功能

    用vue写的 显示,隐藏 hide(){ this.canvas.getActiveObject().set('opacity', 0).setCoords(); this.canvas.reques ...

  10. python第三方库 pip 豆瓣源

    pip install xxx -i http://pypi.douban.com/simple/ xxx 为包名