这题真是个不错的题,一年有2n天,有k个人,至少两人同一天生日的概率,化成最简分数,上下mod1e6+3
首先公式很快可以搞出来1−(2n−1)...(2n−(k−1))2n(k−1)
然后n和k都很大,先要找gcd
gcd肯定是2的幂次,所以就是看1,2,....,k−1里面一共有多少2的因子
这个可以O(logk)求出
gcd=2tmp,可以最后逆元乘上去,2tmp的逆元是2mod−1−(tmp%(mod−1))
然后分子分母可以先模mod,分母很简单,分子的话怎么弄呢,发现如果k−1≥mod,那么分子肯定是0
反之,那就暴力,得到最简的AB
1−AB=B−AB就是答案
代码:
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
#define MAX 200005
#define MAXN 1000005
#define maxnode 205
#define sigma_size 2
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lrt rt<<1
#define rrt rt<<1|1
#define middle int m=(r+l)>>1
#define LL long long
#define ull unsigned long long
#define mem(x,v) memset(x,v,sizeof(x))
#define lowbit(x) (x&-x)
#define pii pair<int,int>
#define bits(a) __builtin_popcount(a)
#define mk make_pair
#define limit 10000
//const int prime = 999983;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f;
//const double pi = acos(-1.0);
const double inf = 1e18;
//const double eps = 1e-9;
const LL mod = 1e6+3;
const ull mx = 133333331;
/*****************************************************/
inline void RI(int &x) {
char c;
while((c=getchar())<'0' || c>'9');
x=c-'0';
while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0';
}
/*****************************************************/
LL qpow(LL a,LL n){
LL ans=1;
while(n){
if(n&1) ans=ans*a%mod;
a=a*a%mod;
n>>=1;
}
return ans;
}
int main(){
//freopen("in.txt","r",stdin);
LL n,k;
while(cin>>n>>k){
int x=0;
while((1LL<<x)<k) x++;
if(x>n){
printf("1 1\n");
continue;
}
LL tmp=0;
for(LL i=2;i<=k-1;i<<=1){
tmp+=(k-1)/i;
}
if(k-1>=mod){
LL fen=qpow(qpow(2,n),k-1)*qpow(2,mod-1-(tmp%(mod-1)))%mod;
cout<<fen<<" "<<fen<<endl;
}
else{
LL fen=qpow(qpow(2,n),k-1)*qpow(2,mod-1-(tmp%(mod-1)))%mod;
LL zi=1;
for(int i=1;i<k;i++){
zi=zi*(qpow(2,n)-i+mod)%mod;
}
zi=zi*qpow(2,mod-1-(tmp%(mod-1)))%mod;
cout<<((fen-zi)%mod+mod)%mod<<" "<<fen<<endl;
}
}
return 0;
}