联赛模拟17_简单的玄学
m个数各不相同概率为 \(\frac{A_{2^n}^{m}}{(2^n)^m}\)
答案就是
\(1-\frac{(2^n)*(2^n-1)...(2^n-m+1)}{(2^n)^m}\)
=\(\frac{(2^n)^m-(2^n)*(2^n-1)...(2^n-m+1)}{(2^n)^m}\)
分子分母先约2,再取模
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define int long long
const int M=1e6+3;
const int phi=1e6+2;
int n,m;
int erncf;
int fz,fm;
int cnt;
int qp(int a,int x){
int ans=1;
while(x){
if(x&1) ans=ans*a%M;
x>>=1,a=a*a%M;
}
return ans;
}
signed main(){
freopen("random.in","r",stdin);
freopen("random.out","w",stdout);
scanf("%lld%lld",&n,&m);
erncf=qp(2,n%phi);// 2的n次方
fm=qp(erncf,m%phi);
fz=1;
for(int i=0;i<m&&fz;++i) fz=fz*(erncf-i)%M;
cnt=n;
for(int i=1;(1ll<<i)<=m-1;++i) cnt+=(m-1)/(1ll<<i);
fz=fz*qp(qp(2,M-2),cnt)%M;
fm=fm*qp(qp(2,M-2),cnt)%M;
printf("%lld %lld\n",(fm-fz+M)%M,fm);
return 0;
}