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.

想要知道答案是啥还是很容易的,用高中知识即可知道1 - {  A(2^n,k) / 2^(nk)  } 即是所求,A(a,b)是排列数。

问题是要先化简再上下同时取模

可以先证明如果有大数A、B,假设(A%mod)/(B%mod)==p/q,那么1-A/B=(B-A)/B=(q-p)/q。(在模mod意义下)

所以只要知道A(2^n,k)/2^(nk),就能知道答案了

先化简。

分式下面只有2,所以gcd=2^t,t不知道,但是显然t是由上面A(2^n,k)决定。

考虑(2^n)(2^n-1)...(2^n-k+1)有多少个因子2。如果把2^n单独考虑,剩下(2^n-1)...(2^n-k+1)的2的因子数跟1~k-1的2的因子数一样多。因为任取个(2^n-s),它能和s对应

所以因子数就是n+(k-1)/2+(k-1)/4+...+(k-1)/2^p,除到(k-1)/2^p=0为止

得到了gcd=2^t的t之后,只要上下同时乘(2关于mod的逆元)乘t次,就完成了化简。

然后注意到当k>=mod时,(2^n)(2^n-1)(2^n-mod+1)%mod==0,由鸽巢原理这是显然的。

所以当k<mod,A(2^n,k)%mod暴力算,k>=mod,A(2^n,k)%mod==0。

而2^(nk)%mod是容易算的。

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
#define mod 1000003
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL n,k;
LL rev_2;
LL bit[];
inline LL quickpow(LL a,LL b,LL MOD)
{
LL s=;
while (b)
{
if (b&)s=(s*a)%MOD;
a=(a*a)%MOD;
b>>=;
}
return s;
}
int main()
{
rev_2=quickpow(,mod-,mod);bit[]=;for (int i=;i<;i++)bit[i]=bit[i-]<<;
n=read();k=read();
if (n<=&&k>bit[n]){puts("1 1");return ;}
if (k==){puts("0 1");return ;}
LL mx=quickpow(,n,mod),now=mx;
LL ans1=,ans2=;
LL te=k-,sum=n;
while (te)
{
sum+=te/;
te>>=;
}
LL sv=k;
for (LL i=;i<=min(sv,(LL)mod);i++)
{
k--;
ans2=(ans2*mx)%mod;
ans1=(ans1*now)%mod;
now--;if (!now)now+=mod;
}
while (k%(mod-)!=)ans2=(ans2*mx)%mod,k--;
ans1=(ans1*quickpow(rev_2,sum,mod))%mod;
ans2=(ans2*quickpow(rev_2,sum,mod))%mod;
printf("%lld %lld\n",(ans2-ans1+mod)%mod,ans2);
//ans=1-{ (2^n*(2^n-1)*(2^n-2)*...*(2^n-k+1))/(2^n)^k }
}

cf 711E

cf711E ZS and The Birthday Paradox的更多相关文章

  1. CF369E. ZS and The Birthday Paradox

    /* cf369E. ZS and The Birthday Paradox http://codeforces.com/contest/711/problem/E 抽屉原理+快速幂+逆元+勒让德定理 ...

  2. codeforces 711E E. ZS and The Birthday Paradox(数学+概率)

    题目链接: E. ZS and The Birthday Paradox. time limit per test 2 seconds memory limit per test 256 megaby ...

  3. ZS and The Birthday Paradox

    ZS and The Birthday Paradox 题目链接:http://codeforces.com/contest/711/problem/E 数学题(Legendre's formula) ...

  4. Codeforces 711E ZS and The Birthday Paradox 数学

    ZS and The Birthday Paradox 感觉里面有好多技巧.. #include<bits/stdc++.h> #define LL long long #define f ...

  5. Codeforces Round #369 (Div. 2) E. ZS and The Birthday Paradox 数学

    E. ZS and The Birthday Paradox 题目连接: http://www.codeforces.com/contest/711/problem/E Description ZS ...

  6. 【Codeforces711E】ZS and The Birthday Paradox [数论]

    ZS and The Birthday Paradox Time Limit: 20 Sec  Memory Limit: 512 MB Description Input Output Sample ...

  7. Codeforces 711E ZS and The Birthday Paradox

    传送门 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output st ...

  8. 【28.57%】【codeforces 711E】ZS and The Birthday Paradox

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. codeforces 711E. ZS and The Birthday Paradox 概率

    已知一年365天找23个人有2个人在同一天生日的概率 > 50% 给出n,k ,表示现在一年有2^n天,找k个人,有2个人在同一天生日的概率,求出来的概率是a/b形式,化到最简形式,由于a,b可 ...

随机推荐

  1. easyui 刷新页面

    window.location.reload()刷新当前页面. parent.location.reload()刷新父亲对象(用于框架) opener.location.reload()刷新父窗口对象 ...

  2. 洛谷 P2353 背单词

    题目背景 小明对英语一窍不通,令老师十分头疼.于是期末考试前夕,小明被逼着开始背单词…… 题目描述 老师给了小明一篇长度为N的英语文章,然后让小明背M个单词.为了确保小明不会在背单词时睡着,老师会向他 ...

  3. Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.entity.ContentType.withCharset(Ljava/lang/String;)Lorg/apache/http/entity/ContentType;

    解决方案是:第一点先检查一下使用的包是否冲突,是否是版本号一致.第二点是增加一个包 忙活了好久才解决了这个异常,小小的激动一下啊啊

  4. Make 学习笔记(1)

    Make 学习笔记(1) 参考: GNU make 学习总结(1) 基础 make是帮助程序员使编译器明白如何编译工程的一种工具; 核心是规则. 规则一般由三部分组成: 目标(target) 必要条件 ...

  5. eclips配置

    新建空workspace import... configMathod:main:project:eFT-Debug@eFTSlnC/C++ Aplication /media/B/testspa2. ...

  6. 【简●解】 LG P2730 【魔板 Magic Squares】

    LG P2730 [魔板 Magic Squares] [题目背景] 在成功地发明了魔方之后,鲁比克先生发明了它的二维版本,称作魔板.这是一张有8个大小相同的格子的魔板: 1 2 3 4 8 7 6 ...

  7. 【树状数组 离散化】bzoj1573: [Usaco2009 Open]牛绣花cowemb

    解方程题! Description Bessie学会了刺绣这种精细的工作.牛们在一片半径为d(1 <= d <= 50000)的圆形布上绣花. 它们一共绣了N (2 <= N < ...

  8. [LUOGU] P2679 子串

    一开始用一个f数组转移,发现不太对,状态有重叠部分 f[i][j][k]表示考虑了s的前i位,匹配到t的第j位,用了k个子串,且s的第i位必选 g[i][j][k]表示考虑了s的前i位,匹配到t的第j ...

  9. Linux基础学习-数据备份工具Rsync

    数据备份工具rsync 作为一个系统管理员,数据备份是非常重要的,如果没有做好备份策略,磁盘损坏了,那么你的数据将全部丢失,所以在日常的维护工作中,一定要时刻牢记给数据做备份. rsync不仅可以可以 ...

  10. Safari不能保存session的处理方法

    在vue单页应用项目中,safari浏览器验证码登陆提示'验证码过期'或者验证码校验不通过的问题 原因:验证码存储在了session里,接着验证时又发起了一次会话,因为Safari不保存cookie, ...