###### Codeforces 711 E. ZS and The Birthday Paradox（数学）——Codeforces Round #369 (Div. 2)
[传送门](http://codeforces.com/contest/711/problem/E)
E. ZS and The Birthday Paradox
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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% 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.

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 = 8 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 = 2 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.

A(2n,k)(2n)k(1)

12n$\frac 1 {2^n}$，所以 k$k$ 个小朋友的生日的概率就是 1(2n)k$\frac 1 {(2^n)^k}$，那么我们现在保证每个小朋友的生日都不是

n!$n!$ 后面有多少个 0$0$，因为分子展开为：

A(2n,k) = (2n)(2n1)(2n2) ... (2nk+1)$A(2^n,k)\ =\ (2^n)*(2^n-1)*(2^n-2)*\ ...\ *(2^n-k+1)$

GCD$GCD$ 以后，我们就进行计算，因为分母好操作就是 n(k1)$n*(k-1)$ 注意用快速乘法小心爆 long long$long \ long$，然后就是分子了，其

My Code$My\ Code：$

/**
2016 - 08 - 30 晚上
Author: ITAK

Motto:

**/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e3+5;
const LL MOD = 1e6+3;
const double eps = 1e-7;
const double PI = acos(-1);
using namespace std;
LL Scan_LL()///输入外挂
{
LL res=0,ch,flag=0;
if((ch=getchar())=='-')
flag=1;
else if(ch>='0'&&ch<='9')
res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')
res=res*10+ch-'0';
return flag?-res:res;
}
int Scan_Int()///输入外挂
{
int res=0,ch,flag=0;
if((ch=getchar())=='-')
flag=1;
else if(ch>='0'&&ch<='9')
res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')
res=res*10+ch-'0';
return flag?-res:res;
}
void Out(LL a)///输出外挂
{
if(a>9)
Out(a/10);
putchar(a%10+'0');
}
LL Multi(LL a, LL b)
{
LL ans = 0;
while(b)
{
if(b & 1)
ans = (ans+a)%(MOD-1);
b>>=1LL;
a = (a+a)%(MOD-1);
}
return ans;
}
LL quick(LL a, LL b)
{
LL ans = 1;
while(b)
{
if(b & 1)
ans = (ans*a) % MOD;
b>>=1LL;
a = (a*a) % MOD;
}
return ans;
}
void Exgcd(LL a, LL b, LL &x, LL &y)
{
if(b == 0)
{
x = 1;
y = 0;
return;
}
LL x1, y1;
Exgcd(b, a%b, x1, y1);
x = y1;
y = x1 - (a/b)*y1;
}
int main()
{
LL Inv, y;
Exgcd(2, MOD, Inv, y);
Inv = (Inv%MOD+MOD)%MOD;
LL n, k;
while(cin>>n>>k)
{
if(n < 63LL)
{
if(k > (1LL<<n))
puts("1 1");
else
{
LL ans = 0, fm = k, tmp;
fm--;
while(fm)
{
fm>>=1LL;
ans += fm;
}
fm = k-1LL;
fm = Multi(n, fm);
fm = (fm-ans)%(MOD-1);
fm = (fm%(MOD-1)+(MOD-1))%(MOD-1);
fm = quick(2LL, fm);
if(k > MOD)
{
cout<<fm<<" "<<fm<<endl;
continue;
}
tmp = quick(2LL, n);
LL fz = 1;
for(LL i=1; i<k; i++)
fz = fz*(tmp-i)%MOD;
fz = (fz%MOD+MOD)%MOD;
fz = fz*quick(Inv, ans)%MOD;
fz = fm - fz;
fz = (fz%MOD+MOD)%MOD;
cout<<fz<<" "<<fm<<endl;
}
}
else
{
LL ans = 0, fm = k, tmp;
fm--;
while(fm)
{
fm>>=1LL;
ans += fm;
}
/** 2^ans 是最大公约数 **/
fm = k-1LL;
fm = Multi(n, fm);
fm = (fm-ans)%(MOD-1);
fm = (fm%(MOD-1)+(MOD-1))%(MOD-1);
fm = quick(2LL, fm);
if(k > MOD)
{
cout<<fm<<" "<<fm<<endl;
continue;
}
tmp = quick(2LL, n);
LL fz = 1;
for(LL i=1; i<k; i++)
fz = fz*(tmp-i)%MOD;
fz = fz*quick(Inv, ans)%MOD;
fz = fm - fz;
fz = (fz%MOD+MOD)%MOD;
cout<<fz<<" "<<fm<<endl;
}
}
return 0;
}


#### Light oj 1104 Birthday Paradox (生日悖论----概率）

2014-02-13 13:54:13

#### Light oj 1104 Birthday Paradox 生日悖论-雀巢原理

2017-08-01 16:28:18

2017-07-31 21:57:35

2016-08-14 15:15:29

#### CodeForces711E ZS and The Birthday Paradox 费马小定理求逆元

2016-09-04 17:03:32

#### Codeforces 711E ZS and The Birthday Paradox(数学)

2016-08-31 11:48:46

2018-01-24 20:26:05

2017-07-31 10:42:18

2016-08-15 11:28:27

2015-04-30 19:29:29

## 不良信息举报

Codeforces 711 E. ZS and The Birthday Paradox（数学）——Codeforces Round #369 (Div. 2)