【题目链接】 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(乘法逆元)的更多相关文章

  1. Codeforces 711E ZS and The Birthday Paradox 数学

    ZS and The Birthday Paradox 感觉里面有好多技巧.. #include<bits/stdc++.h> #define LL long long #define f ...

  2. Codeforces 711E ZS and The Birthday Paradox

    传送门 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output st ...

  3. codeforces 711E. ZS and The Birthday Paradox 概率

    已知一年365天找23个人有2个人在同一天生日的概率 > 50% 给出n,k ,表示现在一年有2^n天,找k个人,有2个人在同一天生日的概率,求出来的概率是a/b形式,化到最简形式,由于a,b可 ...

  4. Codeforces 543D Road Improvement(树形DP + 乘法逆元)

    题目大概说给一棵树,树的边一开始都是损坏的,要修复一些边,修复完后要满足各个点到根的路径上最多只有一条坏的边,现在以各个点为根分别求出修复边的方案数,其结果模1000000007. 不难联想到这题和H ...

  5. 【28.57%】【codeforces 711E】ZS and The Birthday Paradox

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 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 ...

  7. 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 ...

  8. ZS and The Birthday Paradox

    ZS and The Birthday Paradox 题目链接:http://codeforces.com/contest/711/problem/E 数学题(Legendre's formula) ...

  9. CF369E. ZS and The Birthday Paradox

    /* cf369E. ZS and The Birthday Paradox http://codeforces.com/contest/711/problem/E 抽屉原理+快速幂+逆元+勒让德定理 ...

随机推荐

  1. javscript上传图片前预览的方法setPreViewImage()

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 我用的php开发环境是appserv一键安装,通过http://localhost测试成功,但是我有点不清楚的就是为什么访问.php文件要在地址栏上加上localhost(即http://localhost/text.php)才能成功访问?

    这类似于一个域名地址. 因为默认localhost 就是指向本机.所以就用这个来访问自己本地的网页.比如你也可以输入 http://127.0.0.1/text.php http://192.168. ...

  3. Table的分割线偏移量设置 及其 UIEdgeInset详解

    -(void)viewDidLayoutSubviews { if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)] ...

  4. Makefile写法

    概述 -- 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professional的程序员,makef ...

  5. client|server 最简单的聊天

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/socket ...

  6. MySQL read_only选项的作用

    1作用: 从字面意思上看就可以知道这个是把mysql设置为只读,但是这个只读只是针对一般用户而言的,对于root这种用super权限的用户read_only是没有用的. 2设置方式: set glob ...

  7. J2SE知识点摘记(十)

    1.        多线程的同步 2.        同步代码块 即程序中不能有多个线程同时在这两句代码之间执行.(必须两句代码执行完,其他线程才可以公用执行) 同步代码块定义语法如下 ... syn ...

  8. 微软 Office 2010 SP2 正式版下载大全(含简中)

    7月24日消息,微软正式为 Office 2010 和 SharePoint 2010 系列产品发布 SP 2服务包,带来重要更新和修复.除了提供产品补丁,SP2服务包还将提升产品的稳定性.性能以及安 ...

  9. Solr学习(2) Solr4.2.0+IK Analyzer 2012

    Solr学习(二) Solr4.2.0+IK Analyzer 2012 开场白: 本章简单讲述如何在solr中配置著名的 IK Analyzer 分词器. 本章建立在 Solr学习(一)  基础上进 ...

  10. Puppet的执行过程

    图1 Puppet工作流程 1. 客户端Puppetd向Master发起认证请求,或使用带签名的证书. 2. Master告诉Client你是合法的. 3. 客户端Puppetd调用Facter,Fa ...