c语言sscanf函数的用法是什么
313
2022-08-27
Codeforces #369 (Div. 2) E. ZS and The Birthday Paradox (勒让德定理+逆元)
E. ZS and The Birthday Paradox
time limit per test
memory limit per test
input
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%
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
ZS the Coder knows that the answer can be written as an irreducible fraction
. He wants to find the values of A and B
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
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
Since these numbers may be too large, print them modulo 106. Note that A and B must be coprime before their remainders modulo 106
Examples
input
3 2
output
1 8
input
1 3
output
1 1
input
4 3
output
23 128
Note
In the first sample case, there are 23 days in Udayland. The probability that 2 people have the same birthday among 2 people is clearly
, so A = 1, B = 8.
In the second sample case, there are only 21 days in Udayland, but there are 3 people, so it is guaranteed that two of them have the same birthday. Thus, the probability is 1 and A = B = 1.
题解:规定有2^n天,有k个小朋友,问你这些小朋友在这2^n天,至少有两个小朋友的生日在同一天的概率是多少。特判:如果人数多于天数,就一定有至少2个人是同一天的。
如果所有人的生日都不同。那么第一个人的可能是2^n/2^n,第二个人是(2^n-1)/2^n...第k个人是(2^n-(k-1))/2^n.
全部人的生日都不在同一天的概率为:
。那么容斥一下,答案就是1-
。然后就是考虑对这个式子进行约分。观察式子可以发现分子分母的最大公约数肯定是2的幂次方。因为gcd(2^n-x,2^n)=gcd(x,2^n),也是说2^n-x和x的素因子标准分解式中素数2的指数相同。同理:素数2的指数个数与
中的(k−1)!的指数相同。
由勒让德定理(点我)可以求出(K−1)!的素因子标准分解式素数2的指数,然后可以求出分子分母的gcd。当a与p互斥时,a^(p-2)=1/a mod p 或 a^(p-1)=1 mod p。(求逆元)
AC代码:
#pragma comment(linker, "/STACK:102400000,102400000")//#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~