博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #369 (Div. 2) E. ZS and The Birthday Paradox 数学
阅读量:4614 次
发布时间:2019-06-09

本文共 2056 字,大约阅读时间需要 6 分钟。

E. ZS and The Birthday Paradox

题目连接:

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

转载于:https://www.cnblogs.com/qscqesze/p/5827388.html

你可能感兴趣的文章
iOS开发UI篇—UITabBarController简单介绍
查看>>
Android应用程序的安装位置
查看>>
G - SDOI
查看>>
[LeetCode]Reverse Linked List
查看>>
HDU5807 Keep In Touch (BestCoder Round #86 D ) 分布式dp
查看>>
医保接口实现的基本流程
查看>>
pb数据窗口下拉数据窗口列的排序(翻译)
查看>>
Asp.net的__EVENTARGUMENT __EVENTTARGET一些参考网址
查看>>
2019春季第十二周作业
查看>>
Windows10无法打开NVIDA控制面板
查看>>
已经一周没有开锅了
查看>>
Ruby基础笔记
查看>>
oc38--类工厂方法在继承中
查看>>
oc75--不可变字典NSDictionary
查看>>
MySql安装与使用图文教程
查看>>
vue 数据传递的方法
查看>>
MFC 导入EXCEL到数据库
查看>>
[转载]Java同步、异步相关知识点
查看>>
洛谷 P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm
查看>>
DosBox 的 DOSBOX.CONF 的详细配置说
查看>>