Codeforces 711E ZS and The Birthday Paradox(数学)

原创 2016年08月31日 11:48:46

2nkmod1e6+3
1(2n1)...(2n(k1))2n(k1)
nkgcd
gcd21,2,....,k12
O(logk)
gcd=2tmp,2tmp2mod1(tmp%(mod1))
modk1mod0
AB
1AB=BAB


代码:

#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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。

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

[传送门](http://codeforces.com/contest/711/problem/E) E. ZS and The Birthday Paradoxtime limit per test...

Codeforces Problem 711E ZS and The Birthday Paradox(抽屉原理+乘法逆元+费马小定理+组合数+快速幂+概率论)

Codeforces Problem 711E ZS and The Birthday Paradox(抽屉原理+乘法逆元+费马小定理+组合数+快速幂+概率论)...

CodeForces-711E ZS and The Birthday Paradox(勒让德定理+抽屉原理)

E. ZS and The Birthday Paradox time limit per test 2 seconds memory limit per test 256 m...

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

time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandar...

【数论】codeforce711E ZS and The Birthday Paradox

题目大意: 给n和k。 求2^n天,k个人,其中至少两人同一天生日的概率。 1 ≤ n ≤ 1018, 2 ≤ k ≤ 1018 输出分子和分母 MOD 1e6+3 求MOD前,...

codeforces Round#369 div2-E ZS and The Birthday Paradox

题意: 一年中有2^n天,问有k个人至少有两个人生日在同一天的概率,用分数表示。其中n,k 题解:1e6+3为素数。直接求不好求,我们可以总数-不成立的数。不成立的即为k个人中没有一个人的生日在同一...

CodeForces 369 div2 E. ZS and The Birthday Paradox 数论

E. ZS and The Birthday Paradox time limit per test 2 seconds memory limit per test 256 m...

Codeforces #369 (Div. 2) E. ZS and The Birthday Paradox (勒让德定理+逆元)

E. ZS and The Birthday Paradox time limit per test 2 seconds memory limit per test 256 megabytes...

CodeForces 639E Bear and Paradox

CodeForces 639E Bear and Paradox

【Codeforces Round 354 (Div 2)E】【数学 多项式除法 讨论】The Last Fight Between Human and AI 多项式除以x-k是否值整除

E. The Last Fight Between Human and AI time limit per test 1 second memory limit per test 256 me...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces 711E ZS and The Birthday Paradox(数学)
举报原因:
原因补充:

(最多只允许输入30个字)