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可 ...
随机推荐
- C C++每个头文件的功能说
C/C++每个头文件的功能说明 传统 C++ #include <assert.h> //设定插入点 #include <ctype.h> //字符处理 #include &l ...
- win10查看系统启动项,并且禁用
打开任务管理器,有一个叫做start up的选项卡,里面的东西就是启动项. 右键选中需要disable的,然后禁用.
- CodeForces 486B
Let's define logical OR as an operation on two logical values (i. e. values that belong to the set { ...
- docker(部署常见应用):docker部署mysql
上节回顾:docker(部署常见应用):docker部署nginx docker部署mysql:5.7.26 # 下载镜像 docker pull mysql: # 查看镜像 docker image ...
- selenium对浏览器属性操作的方法
最大化 方法一 //指明ChromeDriver路径 System.setProperty(Src_url_string.Chrome_Driver, Src_url_string.Driver_ad ...
- 原型模式(Prototype)C++实现
意图:用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 实用性:1.当要实例化的类是在运行时刻指定时. 2.为了避免创建一个与产品类层次平行的工厂类层次时. 3.当一个类的实例只能有几 ...
- TensorFlow-正弦函数拟合
MNIST的代码还是有点复杂,一大半内容全在搞数据,看了半天全是一滩烂泥.最关键的是最后输出就是一个accuracy,我根本就不关心你准确率是0.98还是0.99好吗?我就想看到我手写一个5,你程序给 ...
- (转)50 个 jQuery 小技巧
1. 如何修改jQuery默认编码(例如默认UTF-8改成改GB2312): $.ajaxSetup({ajaxSettings:{ contentType:"application/x-w ...
- Android Material Design之CollapsingToolbarLayout使用
CollapsingToolbarLayout作用是提供了一个可以折叠的Toolbar,它继承至FrameLayout,给它设置layout_scrollFlags,它可以控制包含在Collapsin ...
- Paint、Canvas.2
1:使用Cavans画个简单图形 2:过程 2.1:绘制最外部的圆 /*** 初始化 paint */ Paint paint; paint = new Paint(); paint.setColor ...