Codeforces #369 (Div. 2) E. ZS and The Birthday Paradox (勒让德定理+逆元)

网友投稿 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#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair pii;typedef vector vi;const double eps = 1e-8; const int INF = 1e9+7; const ll inf =(1LL<<62) ;const ll MOD = 1e6 + 3; const ll mod = (1LL<<32);const int N =110; const int M=100010;const int maxn=1001;#define mst(a) memset(a, 0, sizeof(a))#define M_P(x,y) make_pair(x,y)#define in freopen("in.txt","r",stdin) #define rep(i,j,k) for (int i = j; i <= k; i++) #define per(i,j,k) for (int i = j; i >= k; i--) #define lson x << 1, l, mid #define rson x << 1 | 1, mid + 1, r const int lowbit(int x) { return x&-x; }//const int lowbit(int x) { return ((x)&((x)^((x)-1))); } int read(){ int v = 0, f = 1;char c =getchar();while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();}while(48 <= c && c <= 57) v = v*10+c-48, c = getchar();return v*f;}char a[1010][6];int q_mod(ll a,ll b) { ll ans=1; while(b>0) { if(b&1) ans=(ans*a)%MOD; a=(a*a)%MOD; b>>=1; } return ans; } int main(){ ll n, k; cin>>n>>k; if(n<=62&&k>1ll<>=1) { num+=i/2; } ll b=1; ll a=q_mod(2,n); for(ll i=1;i<=k-1;i++) { ll tmp=(a-i+MOD)%MOD; b=b*tmp%MOD; if(!tmp)break; } ll ans=q_mod( q_mod(2,num), MOD-2 ); a=q_mod(a,k-1); a=a*ans%MOD; b=b*ans%MOD; b=(a-b+MOD)%MOD; printf("%I64d %I64d\n",b,a);}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:精酿啤酒营销技巧!(怎样做好啤酒销售技巧)
下一篇:冬奥TOP赞助商营销遇冷,真的是世界末日吗?(冬奥会品牌赞助)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~