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可 ...
随机推荐
- vim编辑器,管道,输入输出重定向
1.vim的认识及其一些常用指令 a, 认识vim的命令行模式和插入模式: 当vim运行后默认进入该模式,他可以控制屏幕光标的移动,字符.字或行的删除,移动复制某区段及进入Insert mode下,或 ...
- Java中处理异常中return关键字
Java中,执行try-catch-finally语句需要注意: 第一:return语句并不是函数的最终出口,如果有finally语句,这在return之后还会执行finally(return的值会暂 ...
- web安全——系统(Linux)
简介 最小(少)原则,是安全的重要原则.最小的权限,最小的用户,最少的服务,最少的进程,是最安全的. 系统安全包括:文件系统保护.用户管理安全.进程的保护以及日志的管理. 场景 确保服务最少,每个都是 ...
- ASP.NET MVC自定义AuthorizeAttribute篇知识点讲解—登录限制
1.前言 a.微软对ASP.NET的开发从WebForm到MVC的转变,已经正式过去5,6个年头,现在WebForm和MVC也都越来越完善,小小算来我也已经工作了将近三年,从大学的时候学习ASP.NE ...
- js事件小记
参考javascript编程全解 javascript高级程序设计 javascript经典实例 对事件的处理方式称为事件处理程序或事件侦听器 ,对于一个元素或事件,只能设定1个事件处理程序,却可以 ...
- 盒模型结构——3D盒模型
- SharePoint 使用代码为页面添加WebPart
传统的SharePoint实施中,我们通常会创建SharePoint页面,然后添加webpartzone,而后在上面添加webpart:但是有些情况下,也要求我们使用代码,将webpart添加到相应w ...
- Force.com微信开发系列(四)申请Access Token及自定义菜单之创建菜单
在微信接口开发中,许多服务的使用都离不开Access Token,Access Token相当于打开这些服务的钥匙,正常情况下会在7200秒内失效,重复获取将导致上次获取的Token失效,本文将首先介 ...
- oc 字符串
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- UIWebView用法详解及代码分享
今天我们来详细UIWebView用法.UIWebView是iOS内置的浏览器控件,可以浏览网页.打开文档等 能够加载html/htm.pdf.docx.txt等格式的文件. 用UIWebView我们就 ...