CF369E. ZS and The Birthday Paradox
- /*
- cf369E. ZS and The Birthday Paradox
- http://codeforces.com/contest/711/problem/E
- 抽屉原理+快速幂+逆元+勒让德定理+费马小定理+欧拉定理+数论
- 题解:https://amoshyc.github.io/ojsolution-build/cf/cf369/pe.html
- 坑点:
- 1、long long 类型的常量一定要加LL,否则1<<n只在int范围内
- 2、带模的题目,最后一定要判断是否答案为负,答案为负数要加mod
- */
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- const int mod=;
- long long n,k;
- long long Legendre(long long n,long long p)//勒让德定理:O(logn) 算出n!中有多少个p
- {
- long long ans=;
- while(n>)
- {
- ans+=n/p;
- n/=p;
- }
- return ans;
- }
- long long pow(long long base,long long n)
- {
- long long ans=;
- base=base%mod;//先取模防止爆long long
- while(n>)
- {
- if(n&)
- ans=(ans*base)%mod;
- base=(base*base)%mod;
- n>>=;
- }
- return ans;
- }
- int main()
- {
- //freopen("cf711E.in","r",stdin);
- scanf("%I64d%I64d",&n,&k);
- if(n<= && k>(1LL<<n))//抽屉原理
- {
- printf("1 1\n");
- return ;
- }
- long long gcd=Legendre(k-,);
- long long p=,q;//p/q;
- q=((n%(mod-))*((k-)%(mod-))-gcd%(mod-))%(mod-)+mod-;//欧拉函数降幂
- //q=(n%(mod-1))*((k-1)%(mod-1))+mod-1-gcd; this is a wrong way!!!!!!
- q=pow(,q)%mod;//q=2^( n(k-1)-gcd ) <=> 2^((n(k-1)-gcd)%phi(mod)+phi(mod) );
- if(k->=mod)//抽屉原理得出在分子中必定存在一个%mod=0,标程大坑,不能直接输出1 1,即此处不约分。
- p=;
- else
- {
- long long val=pow(,n);
- for(long long i=;i<=k-;i++)
- {
- p=(p*((val-i))%mod)%mod;
- }
- if(gcd)
- {
- p=(p*pow(pow(,gcd),mod-))%mod;
- //p=(p+mod)/pow(2,gcd);
- }
- }
- p=q-p;
- if(p<)//判断是否为负
- p+=mod;
- printf("%I64d %I64d\n",p,q);
- return ;
- }
CF369E. ZS and The Birthday Paradox的更多相关文章
- 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 ...
- ZS and The Birthday Paradox
ZS and The Birthday Paradox 题目链接:http://codeforces.com/contest/711/problem/E 数学题(Legendre's formula) ...
- Codeforces 711E ZS and The Birthday Paradox 数学
ZS and The Birthday Paradox 感觉里面有好多技巧.. #include<bits/stdc++.h> #define LL long long #define f ...
- 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 ...
- 【Codeforces711E】ZS and The Birthday Paradox [数论]
ZS and The Birthday Paradox Time Limit: 20 Sec Memory Limit: 512 MB Description Input Output Sample ...
- Codeforces 711E ZS and The Birthday Paradox
传送门 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output st ...
- cf711E ZS and The Birthday Paradox
ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that g ...
- 【28.57%】【codeforces 711E】ZS and The Birthday Paradox
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- codeforces 711E. ZS and The Birthday Paradox 概率
已知一年365天找23个人有2个人在同一天生日的概率 > 50% 给出n,k ,表示现在一年有2^n天,找k个人,有2个人在同一天生日的概率,求出来的概率是a/b形式,化到最简形式,由于a,b可 ...
随机推荐
- 准备开源用javascript写Tomcat下的WebApp的项目
原创文章,转载请注明. 这个想法由来已久.用javascript编写Tomcat下的WebApp.现现在也有alpha版本号的实现. 这种话,前端程序猿就能够像用Node.js那样,用javascri ...
- SQL Server数据库 bcp导出备份文件应用
/** * 授权 */ EXEC sp_configure 'show advanced options',1; go reconfigure; go exec sp_configure 'xp_ ...
- CNN中的局部连接(Sparse Connectivity)和权值共享
局部连接与权值共享 下图是一个很经典的图示,左边是全连接,右边是局部连接. 对于一个1000 × 1000的输入图像而言,如果下一个隐藏层的神经元数目为10^6个,采用全连接则有1000 × 1000 ...
- [HTML&CSS] 条件注释判断浏览器
<!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--><!--[if IE]> 所有的IE可识别 <![e ...
- 对JVM还有什么不懂的?一文章带你深入浅出JVM!
本文跟大家聊聊JVM的内部结构,从组件中的多线程处理,JVM系统线程,局部变量数组等方面进行解析 JVM JVM = 类加载器(classloader) + 执行引擎(execution engine ...
- History of the browser user-agent string--转
https://webaim.org/blog/user-agent-string-history/ In the beginning there was NCSA Mosaic, and Mosai ...
- 通过阅读《React 进阶之路》之学习笔记
第一章: React 通过引入虚拟DOM.状态.单向数据流等设计理念,形成以组件为核心,用组件搭建UI的开发模式.
- html中map标签和area标签的应用
map标签的用途:是与img标签绑定使用的,常被用来赋予给客户端图像某处区域特殊的含义,点击该区域可跳转到新的文档. 因为map标签是与img标签绑定使用的,所以我们需要给map标签添加ID和name ...
- fabric.js 翻转,复制粘贴,隐藏, 删除,历史记录,撤销, 剪切, 图层,组合打散,锁定等功能
用vue写的 显示,隐藏 hide(){ this.canvas.getActiveObject().set('opacity', 0).setCoords(); this.canvas.reques ...
- python第三方库 pip 豆瓣源
pip install xxx -i http://pypi.douban.com/simple/ xxx 为包名