题目链接:

E. ZS and The Birthday Paradox

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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?

Input

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.

Output

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.

Examples
input
3 2
output
1 8
input
1 3
output
1 1
input
4 3
output
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(数学+概率)的更多相关文章

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

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

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

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

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

  4. ZS and The Birthday Paradox

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

  5. CF369E. ZS and The Birthday Paradox

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

  6. 【Codeforces711E】ZS and The Birthday Paradox [数论]

    ZS and The Birthday Paradox Time Limit: 20 Sec  Memory Limit: 512 MB Description Input Output Sample ...

  7. Codeforces 711E ZS and The Birthday Paradox

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

  8. Codeforces 711E ZS and The Birthday Paradox(乘法逆元)

    [题目链接] http://codeforces.com/problemset/problem/711/E [题目大意] 假设一年有2^n天,问k个小朋友中有两个小朋友生日相同的概率. 假设该概率约分 ...

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

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

随机推荐

  1. Hibernate中的一对一关联和组件的映射

    Hibernate提供了两种映射一对一映射关联关系的方式: 01.按照外键映射 02.按照主键映射 下面以员工账号表和员工档案表(员工账号和档案表之间是一对一的关系)为例,介绍这两种映射关系,并使用这 ...

  2. JavaScript调Java

    1.映射Java对象到JavaScript对象上 MainActivity.java package com.example.jsdemo; import android.os.Bundle; imp ...

  3. web安全——防火墙

    简介 用于实现服务器(Linux)的访问控制的功能的. 分硬件和软件防火墙. 主要是控制访问的流入和服务器的流出. 通过黑名单和白名单的思想来实现更细粒度的控制,这个一般结合其他的应用来定义策略实现. ...

  4. rabbitmq+ keepalived+haproxy高可用集群详细命令

    公司要用rabbitmq研究了两周,特把 rabbitmq 高可用的研究成果备下 后续会更新封装的类库 安装erlang wget http://www.gelou.me/yum/erlang-18. ...

  5. 用构造函数创建对象时的this的指向问题

    用构造函数方式创建对象: function Person(name,age){ this.name=name; this.age=age; this.sayname=function(){ alert ...

  6. MSCRM 迁移 数据库 服务器

    Move the Microsoft Dynamics CRM databases to another SQL Server and SQL Server Reporting Services se ...

  7. SharePoint 2013 内容部署功能简介

    在之前的项目中,当客户有新的需求的时候,我们通常在测试环境上开发或者实施,然后手动在生产环境再弄一次.当发现内容部署这个东西,才知道这样是多么不合理的.我们可以创建两个网站集,一个用来修改,然后通过计 ...

  8. batch_size 和 fetch_size作用

    hibernate抓取策略,,batch-szie在<class>上的应用 batch-size属性,可以批量加载实体类, hbm.xml classes.hbm.xml <?xml ...

  9. IOS杂笔- 7(类方法load与initialize的区别 浅析)

    在介绍两种类方法之前,NSObject Class Reference里对这两个方法说明: +(void)initialize The runtime sends initialize to each ...

  10. 干货-iOS、mac开源项目及库,以后我也会持续更新。

    昨晚在网上看的干货,直接分享给大家了,觉得有用的,直接fork吧. https://github.com/Brances/TimLiu-iOS