zoukankan      html  css  js  c++  java
  • 联赛模拟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
    ",(fm-fz+M)%M,fm);
    	return 0;
    }
    
  • 相关阅读:
    BZOJ 4010: [HNOI2015]菜肴制作( 贪心 )
    bzoj 1084
    bzoj 2763
    bzoj 1003
    bzoj 1858
    codevs 1296
    cf 438D
    vijos 1083
    codevs 3303
    bzoj 1296
  • 原文地址:https://www.cnblogs.com/Lour688/p/13821353.html
Copyright © 2011-2022 走看看