[mine806]

The meaning of problems: the hands of each person has a number, in the range [1,2 ^ n], k indicates the individual, the presence of two people have provided the most simple form of a probability score is the same number a / b, a and b are seeking mode 1e6 + 3,1 <= n, k <= 1e18
 
First is the probability $ 1- \ sum_ {i = 0 } ^ {k-1} (2 ^ {n} -i) / 2 ^ {nk} $, obviously must be the greatest common divisor of two power of two, may assume $ 1 <k <2 ^ { n} $ ( direct output is not within the range), then the power of 2 is $ \ sum_ {i = 1} ^ {60} (m-1) / 2 ^ {i} + n $, i.e. divided by the value of the numerator and denominator must
take into account the Fermat's little theorem: $ 2 ^ {P-1 } \ equiv 1 (mod \ P) $, you can quickly calculate the denominator (and divisor); In addition, when K > = P, in a $ (2 ^ {n} -K + 1,2 ^ {n}] $ there must be a multiple of P and not be eliminate, certain molecules is 0, and use a subtracted digital
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 #define mod 1000003
 5 int s,a,b,mi[mod];
 6 ll n,k;
 7 int main(){
 8     scanf("%lld%lld",&n,&k);
 9     if ((n<=60)&&((1LL<<n)<=k)){
10         printf("1 1");
11         return 0;
12     }
13     for(int i=1;i<61;i++)s=(s+(k-1)/(1LL<<i))%(mod-1);
14     mi[0]=1;
15     for(int i=1;i<mod;i++)mi[i]=mi[i-1]*2%mod;
16     n%=mod-1;
17     s=(s+n)%(mod-1);
18     if (k>=mod)a=0;
19     else{
20         a=1;
21         for(int i=0;i<k;i++)a=1LL*a*(mi[n]-i)%mod;
22         for(int i=1;i<=s;i++)a=a*(mod+1LL)/2%mod;
23     }
24     b=mi[(k%(mod-1)*n%(mod-1)-s+mod-1)%(mod-1)];
25     a=(b-a+mod)%mod;
26     printf("%d %d",a,b);
27 } 
View Code

 

Guess you like

Origin www.cnblogs.com/PYWBKTDA/p/11290547.html