首页 技术 正文
技术 2022年11月18日
0 收藏 968 点赞 2,288 浏览 1998 个字

E. ZS and The Birthday Paradox

题目连接:

http://www.codeforces.com/contest/711/problem/E

Description

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 of 2n 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 modulo 106 + 3 are taken.

Sample Input

3 2

Sample Output

1 8

Hint

题意

有\(2^n\)天,有\(k\)个小朋友,问你这些小朋友在这n天,至少有两个小朋友的生日在同一天的概率是多少,分子分母 mod 1e6+3

题解:

首先容斥,这个很简单。

最难的就是约分,然后我们考虑约分这个玩意儿,他肯定是除以gcd,显然gcd是2的幂,分母的幂显然比分子多,那么我统计一下分子有多少个2 就好了

如果k>=mod,显然答案为0,否则我就暴力。

然后就完了。

特判掉,人比天数多的情况

代码

#include<bits/stdc++.h>
using namespace std;
const int mod = 1e6+3;
long long quickpow(long long m,long long n,long long k)//返回m^n%k
{
long long b = 1;
while (n > 0)
{
if (n & 1)
b = (b*m)%k;
n = n >> 1 ;
m = (m*m)%k;
}
return b;
}
long long gcd(long long a,long long b)
{
if(b==0)return a;
return gcd(b,a%b);
}
int main()
{
long long n,k;
cin>>n>>k;
if(n<62&&k>(1LL<<n))return puts("1 1"),0;
long long num = n;
for(long long i=1;i<62;i++)
num+=(k-1)/(1LL<<i);
long long A=1;
if(k<mod)
{
for(long long i=1;i<=k;i++)A=A*(quickpow(2,n,mod)-i+mod+1)%mod;
A=A*quickpow(quickpow(2,mod-2,mod),num,mod)%mod;
}
else
A=0;
long long B = quickpow(quickpow(2,n,mod),k,mod)*quickpow(quickpow(2,mod-2,mod),num,mod)%mod;
cout<<(B-A+mod)%mod<<" "<<B<<endl;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,956
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,480
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,327
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,110
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,741
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,776