0
点赞
收藏
分享

微信扫一扫

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 

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

. 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 

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

 (A ≥ 0, B ≥ 1, 

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

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

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

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

全部人的生日都不在同一天的概率为:

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

。那么容斥一下,答案就是1- 

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

。然后就是考虑对这个式子进行约分。观察式子可以发现分子分母的最大公约数肯定是2的幂次方。因为gcd(2^n-x,2^n)=gcd(x,2^n),也是说2^n-x和x的素因子标准分解式中素数2的指数相同。同理:素数2的指数个数与

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

中的(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<bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <bitset>
#include <iomanip>
#include <list>
#include <stack>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> 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<<n)
{
puts("1 1");
return 0;
}
ll num=0;
for(ll i=k-1;i;i>>=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);
}



举报

相关推荐

0 条评论