【题目链接】 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. leetcode Remove Element python

    class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] ...

  2. ArrayList与LinkedList时间复杂度之对比

    package ArrayList; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections ...

  3. background:url 的使用方法

    #pingfen li{ width:27px; float:left; height:28px; cursor:pointer; background:url( ; list-style:none; ...

  4. 走进C标准库(4)——"stdio.h"中的putc

    花了点时间把园子弄得好看了点,现在继续. 函数名: putc 功  能: 输出一字符到指定流中 用  法: int putc(int ch, FILE *stream); #define _putc_ ...

  5. Makefile写法

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

  6. Oracle EBS-SQL (SYS-8):职责定义明细.sql

    SELECT DISTINCT fa.application_short_name 模块,                 b.responsibility_name 职责名称, fa.applica ...

  7. wpf中的触发器详解

    原文 http://zwkufo.blog.163.com/blog/static/25882512009724113250883/ 7.1.2 简单逻辑的表示--触发器(1) 在本章的多处介绍中都会 ...

  8. POJ 2686 Traveling by Stagecoach 壮压DP

    大意是有一个人从某个城市要到另一个城市(点数<=30) 然后有n个马车票,相邻的两个城市走的话要消耗掉一个马车票. 花费的时间呢,是马车票上有个速率值,用边/速率就是花的时间. 问最后这个人花费 ...

  9. 《Linux 设备驱动程序》读后感。 并发,竞态,死锁。

    1. 概念 并发:在操作系统中,是指一个时间段中有几个程序都处于已启动运行到运行完毕之间,且这几个程序都是在同一个处理机上运行,但任一个时刻点上只有一个程序在处理机上运行. 来源: 1. Linux ...

  10. 引入css ,使用@import和link的方式

    我们也经常听到有人说要使用link来引入CSS更好,但是你知道为什么吗? 继续往下看 linklink就是把外部CSS与网页连接起来. @importimport文字上与link的区别就是它可以把在一 ...