Codeforces 711E ZS and The Birthday Paradox(乘法逆元)
【题目链接】 http://codeforces.com/problemset/problem/711/E
【题目大意】
假设一年有2^n天,问k个小朋友中有两个小朋友生日相同的概率。
假设该概率约分后为 p / q ,输出p , q对1000003取模的解。
【题解】
当k比天数要大时是肯定成立的,否则答案为1-A(2n,k) / (2n)k,
考虑A(2n,k)=2n*(2n-1)*……*(2n-k+1),所以分子和分母的最大公约数是2的幂次,暴力计算分子分母,以及计算最大公约数的逆元,就可以计算出答案。
【代码】
#include <cstdio>
typedef long long ll;
ll n,k;
const ll mod=1000003;
ll pow(ll a,ll b,ll p){ll t=1;for(a%=p;b;b>>=1LL,a=a*a%p)if(b&1LL)t=t*a%p;return t;}
int main(){
scanf("%I64d%I64d",&n,&k);
if(n<=62&&k>1ll<<n){puts("1 1");return 0;}
ll num=0; for(ll i=k-1;i;i>>=1)num+=i/2;
ll b=1,a=pow(2,n,mod);
for(ll i=1;i<=k-1;i++){
ll tmp=(a-i+mod)%mod;
b=b*tmp%mod;
if(!tmp)break;
}ll inv=pow(pow(2,num,mod),mod-2,mod);
a=pow(a,k-1,mod);
a=a*inv%mod; b=b*inv%mod;
b=(a-b+mod)%mod;
printf("%I64d %I64d\n",b,a);
return 0;
}
Codeforces 711E ZS and The Birthday Paradox(乘法逆元)的更多相关文章
- Codeforces 711E ZS and The Birthday Paradox 数学
ZS and The Birthday Paradox 感觉里面有好多技巧.. #include<bits/stdc++.h> #define LL long long #define f ...
- 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 概率
已知一年365天找23个人有2个人在同一天生日的概率 > 50% 给出n,k ,表示现在一年有2^n天,找k个人,有2个人在同一天生日的概率,求出来的概率是a/b形式,化到最简形式,由于a,b可 ...
- Codeforces 543D Road Improvement(树形DP + 乘法逆元)
题目大概说给一棵树,树的边一开始都是损坏的,要修复一些边,修复完后要满足各个点到根的路径上最多只有一条坏的边,现在以各个点为根分别求出修复边的方案数,其结果模1000000007. 不难联想到这题和H ...
- 【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 E. ZS and The Birthday Paradox(数学+概率)
题目链接: E. ZS and The Birthday Paradox. time limit per test 2 seconds memory limit per test 256 megaby ...
- 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 抽屉原理+快速幂+逆元+勒让德定理 ...
随机推荐
- 出现java.lang.NoSuchFieldException resourceEntries错误的解决方法
JSP表单里面的表单输入<input type= "text" name="user">这里面的每一个输入都是一个Attribute,相当于setA ...
- QF——OC数组
OC中的数组: OC中的数组和它的字符串有很多相似之处.也分为可变和不可变. NSArray:不可变数组,一经初始化,便不能再更改: NSMutableArray:可变数组,它其实是继承于NSArra ...
- 我定制的jquery ui主题
打开网址 http://jqueryui.com/themeroller/,找到Gallery找到Redmond点击edit 将圆角设置成3px,让圆角更低调:将下面的每个Background的背景图 ...
- 练习-checkbox 全选 ,反选, 单选,以及取值
1.方法1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w ...
- 给js文件传递参数
一.利用全局变量 这是最简单的一种方式,比如Google Adsense: <script type="text/javascript"> google_ad_clie ...
- Oracle EBS-SQL (BOM-4):检查期间新增编码总数.sql
selectFU.description 创建者,msi.CREATION_DATE ...
- 几家SIEM
HP Arcsight Imperva is a HP Business Partner. HP is the world's largest IT company, providing infras ...
- js获取宽度设置thickbox百分比
thickbox的宽高不好设为百分比,这样遇到不同的尺寸的电脑就会出现问题. 怎么做呢? 通过js来处理. <script type="text/javascript"> ...
- javascript 中 keyup、keypress和keydown事件
keyup.keypress和keydown事件都是有关于键盘的事件 1. keydown事件在键盘的键被按下的时候触发,keyup 事件在按键被释放的时候触发 keydown.keypress ...
- CodeForces - 61E Enemy is weak
Description The Romans have attacked again. This time they are much more than the Persians but Shapu ...