ZS and The Birthday Paradox

题目:一年有2^n天,有k个人,他们的生日有冲突的概率是多少?答案用最简分数表示,分子分母对1e6+3取模。1 ≤ n ≤ 10^18, 2 ≤ k ≤ 10^18。

答案为 1 - A(2^n,k) / (2^n)^k,分子与分母的gcd必定为2^i。计算A(2^n,k)=(2^n) * (2^n-1) * ... * (2^n-k+1)含多少个因子2,相当于计算0~k-1中总共有多少个因子2。

因为分子乘以了模mod后就永远是0了,所以可以O(mod)的算出分子。求出gcd后乘上gcd的逆元就可以了。

 #include <map>
#include <set>
#include <stack>
#include <queue>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#define eps 1e-15
#define PI acos(-1)
#define INF 100000007
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define mem(a) memset(a,0,sizeof(a))
#define N 400005
#define P 1000003
long long n,k,i,p,q,x,ans,kk,ny; long long pow(long long a,long long b)
{
long long ans=;
while (b>)
{
if (b&==)
ans=(ans*a)%P;
b>>=;
a=(a*a)%P;
}
return ans;
}
int main()
{
scanf("%I64d%I64d",&n,&k);
if (n<)
{
if ((1ll<<n)<k)
{
printf("1 1\n");
return ;
} }
x=pow(,n);
p=;
for (i=;i<k;i++)
{
x--;
p=(p*x)%P;
if (p==) break;
}
kk=k-;
while (kk>)
{
ans+=kk/;
kk=kk>>;
}
ny=pow(pow(,P-),ans);
p=(p*ny)%P;
q=(pow(pow(,n),k-)*ny)%P;
p=q-p;
if (p<)p+=P;
printf("%I64d %I64d\n",p,q);
return ;
}
# When Who Problem Lang Verdict Time Memory
20280606 2016-08-30 16:20:59 lbz007 E - ZS and The Birthday Paradox GNU C++ Accepted 31 ms 0 KB

Codeforces Round #369 (Div. 2)E的更多相关文章

  1. Codeforces Round #369 (Div. 2)---C - Coloring Trees (很妙的DP题)

    题目链接 http://codeforces.com/contest/711/problem/C Description ZS the Coder and Chris the Baboon has a ...

  2. Codeforces Round #369 (Div. 2) C. Coloring Trees(dp)

    Coloring Trees Problem Description: ZS the Coder and Chris the Baboon has arrived at Udayland! They ...

  3. Codeforces Round #369 (Div. 2) C. Coloring Trees(简单dp)

    题目:https://codeforces.com/problemset/problem/711/C 题意:给你n,m,k,代表n个数的序列,有m种颜色可以涂,0代表未涂颜色,其他代表已经涂好了,连着 ...

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

    E. ZS and The Birthday Paradox 题目连接: http://www.codeforces.com/contest/711/problem/E Description ZS ...

  5. Codeforces Round #369 (Div. 2) D. Directed Roads 数学

    D. Directed Roads 题目连接: http://www.codeforces.com/contest/711/problem/D Description ZS the Coder and ...

  6. Codeforces Round #369 (Div. 2) C. Coloring Trees 动态规划

    C. Coloring Trees 题目连接: http://www.codeforces.com/contest/711/problem/C Description ZS the Coder and ...

  7. Codeforces Round #369 (Div. 2) B. Chris and Magic Square 水题

    B. Chris and Magic Square 题目连接: http://www.codeforces.com/contest/711/problem/B Description ZS the C ...

  8. Codeforces Round #369 (Div. 2) A. Bus to Udayland 水题

    A. Bus to Udayland 题目连接: http://www.codeforces.com/contest/711/problem/A Description ZS the Coder an ...

  9. Codeforces Round #369 (Div. 2) D. Directed Roads —— DFS找环 + 快速幂

    题目链接:http://codeforces.com/problemset/problem/711/D D. Directed Roads time limit per test 2 seconds ...

  10. Codeforces Round #369 (Div. 2) A. Bus to Udayland (水题)

    Bus to Udayland 题目链接: http://codeforces.com/contest/711/problem/A Description ZS the Coder and Chris ...

随机推荐

  1. LG_2051_[AHOI2009]中国象棋

    题目描述 这次小可可想解决的难题和中国象棋有关,在一个N行M列的棋盘上,让你放若干个炮(可以是0个),使得没有一个炮可以攻击到另一个炮,请问有多少种放置方法.大家肯定很清楚,在中国象棋中炮的行走方式是 ...

  2. CF580D_Kefa and Dishes

    D. Kefa and Dishes time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. <JZOJ5938>分离计划

    emm骚操作 #include<cstdio> #include<iostream> #include<cstring> #include<algorithm ...

  4. Spring Boot 之 Redis详解

    Redis是目前业界使用最广泛的内存数据存储. Redis支持丰富的数据结构,同时支持数据持久化. Redis还提供一些类数据库的特性,比如事务,HA,主从库. REmote DIctionary S ...

  5. 将配置好的虚拟机文件导入VMware

    第一步:打开VMware Workstation Pro 第二步:  选择文件,图示: 第三步:点击打开,选择配置好的虚拟机文件目录 点击打开就ok了,图示

  6. classnames

    在React中编写模板时给标签添加class. 如果是固定的className="XX"就可以了. 如果要根据状态值动态应用或去除, 或使用多个class时就麻烦了. 可以使用cl ...

  7. 深入理解Tomcat(12)拾遗

    前言 如何使用? 源码解读 总结 前言 Tomcat为了提高性能,在接受到socket传入的字节之后并不会马上进行编码转换,而是保持byte[]的方式,在用到的时候再进行转换.在tomcat的实现中, ...

  8. 马云也看好!VR在2016年能否得到质变

    在2015年10月底有消息传出,国外虚拟现实公司Magic Lea的新一轮融资吸引到中国互联网巨鳄--阿里巴巴公司的关注.据透露,阿里巴巴极有可能为Magic Lea投资2亿美元.这虽然是阿里巴巴第一 ...

  9. Hihocoder1456 Rikka with Lattice

    众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的:勇太有一个$n times m$的点阵,他想要从这$n times m$个点中选出三个点 ${A,B,C}$,满足 ...

  10. C++中cin的输入分隔符问题及相关

    1.C/C++中的类型转换函数(区分类中的类型转换构造函数): 头文件:C中stdlib.h C++中cstdlib atof(将字符串转换成浮点型数) atoi(将字符串转换成整型数) atol(将 ...