codeforces 711E E. ZS and The Birthday Paradox(数学+概率)
题目链接:
E. ZS and The Birthday Paradox、
2 seconds
256 megabytes
standard input
standard output
ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and decides to test this with the inhabitants of Udayland.
In Udayland, there are 2n days in a year. ZS the Coder wants to interview k people from Udayland, each of them has birthday in one of2n days (each day with equal probability). He is interested in the probability of at least two of them have the birthday at the same day.
ZS the Coder knows that the answer can be written as an irreducible fraction
. He wants to find the values of A and B (he does not like to deal with floating point numbers). Can you help him?
The first and only line of the input contains two integers n and k (1 ≤ n ≤ 1018, 2 ≤ k ≤ 1018), meaning that there are 2n days in a year and that ZS the Coder wants to interview exactly k people.
If the probability of at least two k people having the same birthday in 2n days long year equals
(A ≥ 0, B ≥ 1,
), print the A and B in a single line.
Since these numbers may be too large, print them modulo 106 + 3. Note that A and B must be coprime before their remainders modulo106 + 3 are taken.
3 2
1 8
1 3
1 1
4 3
23 128 题意: 一年有2^n天,现在有k个熊孩子,问至少有两个熊孩子的生日是同一天的概率是多少; 思路: 1-2^n*(2^n-1)*...*(2^n-k+1)/(2^n)^k,然后就是求gcd了,约分后再求逆元,反正这个题涉及的知识点有概率论与组合数学,抽屉原理,勒让德定理,求逆元,快速幂这些,反正我是看别人代码才会的,我好菜啊; AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e6+3;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=2e5+10;
const int maxn=1e3+520;
const double eps=1e-12; LL n,k; int check()
{
LL s=1;
for(int i=1;i<=n;i++)
{
s=s*2;
if(s>=k)return 0;
}
return 1;
}
LL pow_mod(LL x,LL y)
{
LL s=1,base=x;
while(y)
{
if(y&1)s=s*base%mod;
base=base*base%mod;
y>>=1;
}
return s;
}
int main()
{
read(n);read(k);
if(check()){cout<<"1 1\n";return 0;}
LL num=0;
for(LL i=k-1;i>0;i/=2)num+=i/2;
LL temp=pow_mod(2,n),ans=1;
for(LL i=1;i<k;i++)
{
ans=ans*(temp-i)%mod;
if(temp-i==0)break;
}
LL ha=pow_mod(2,num);
ans=ans*pow_mod(ha,mod-2)%mod;
temp=pow_mod(temp,k-1)*pow_mod(ha,mod-2)%mod;
cout<<(temp-ans+mod)%mod<<" "<<temp<<endl; return 0;
}
codeforces 711E E. ZS and The Birthday Paradox(数学+概率)的更多相关文章
- 【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 数学
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 ...
- ZS and The Birthday Paradox
ZS and The Birthday Paradox 题目链接:http://codeforces.com/contest/711/problem/E 数学题(Legendre's formula) ...
- CF369E. ZS and The Birthday Paradox
/* cf369E. ZS and The Birthday Paradox http://codeforces.com/contest/711/problem/E 抽屉原理+快速幂+逆元+勒让德定理 ...
- 【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 ...
- Codeforces 711E ZS and The Birthday Paradox(乘法逆元)
[题目链接] http://codeforces.com/problemset/problem/711/E [题目大意] 假设一年有2^n天,问k个小朋友中有两个小朋友生日相同的概率. 假设该概率约分 ...
- codeforces 711E. ZS and The Birthday Paradox 概率
已知一年365天找23个人有2个人在同一天生日的概率 > 50% 给出n,k ,表示现在一年有2^n天,找k个人,有2个人在同一天生日的概率,求出来的概率是a/b形式,化到最简形式,由于a,b可 ...
随机推荐
- Picasso
1.简介 Picasso是Square公司出品的一个强大的图片下载和缓存图片库1)在adapter中需要取消已经不在视野范围的ImageView图片资源的加载,否则会导致图片错位,Picasso已经解 ...
- 简单封装cookie操作
1 //设置cookie 2 function setCookie(name, value, day) { 3 var oDate = new Date(); 4 oDate.setDate(oDat ...
- Play 可以做的 5 件很酷的事
Play 可以做的 5 件很酷的事 本章译者:@Playframwork 通过 5 个实例,透视 Play 框架背后的哲学. 绑定 HTTP 参数到 JAVA 方法参数 用 Play 框架,在 Jav ...
- iscroll性能
iscroll是比较耗性能的,在iPhone和性能比较好的机是比较流畅的,在性能低的手机就会出现卡的情况.所以如果不想出现这种情况,只有不使用iscroll,囧.
- owl-carousel轮播插件的使用
插件github地址:https://github.com/OwlFonk/OwlCarousel: 插件官网演示地址:http://owlgraphic.com/owlcarousel/: 1.选择 ...
- jQuery 的 ajax
jQuery load() 方法 jQuery load() 方法是简单但强大的 AJAX 方法. load() 方法从服务器加载数据,并把返回的数据放入被选元素中. $(selector).load ...
- ABAP中正则表达式的简单使用方法 (转老白BLOG)
在一个论坛上面看到有人在问正则表达式的问题,特举例简单说明一下.另外,REPLACE也支持REGEX关键字.最后:只能是ECC6或者更高版本才可以(ABAP supports POSIX regula ...
- Fragment官方解析
由于fragment和activity的生命周期很类似,对activity不熟悉的可以参考–深入了解Activity-生命周期, 深入理解Activity-任务,回退栈,启动模式, 概要 A Frag ...
- Cent OS 6.4安装mysql
Cent OS6.4 RPM安装mysql 一.卸载掉原有mysql 因为目前主流Linux系统版本基本上都集成了mysql数据库在里面 如下命令来查看我们的操作系统上是否已经安装了mysql数据库 ...
- 如何获取QQ里的截图app?
电脑系统平台:OS X EI Capitan 10.11 在以前的旧的QQ版本,QQ的截图的偏好还有一个开机自启动的选项: 现在新的版本,却没有了"开机自动运行"的选项,然而有时候 ...