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. 无标定量|有标定量|谱图计数|XIC|AMT数据库|RT对对齐|母离子|子离子|SILVER|SRM|iBAQ|APEX|差异蛋白筛选|MaxQuant|PANDA|C-HPP

    生物医学大数据-蛋白质定量 现今肽段定量效率存在巨大差异.比如相同质量蛋白质,但是肽段和蛋白信号不均一,在物理条件一致时,仅有70%的重复率,并且当重复次数变多时,overlapping在变少. 无标 ...

  2. hadoop创建两大错误:Bad connection to FS. command aborted. exception和Shutting down NameNode at hadoop

    1.问题目录表: Error代码   failed on connection exception: java.net.ConnectException: Connection refused 3.  ...

  3. tomcat启动不了的问题

    tomcat启动的几个问题 1.端口冲突 2.非端口冲突,需要加入配置host文件 日志文件: 解决办法:https://blog.csdn.net/u012949658/article/detail ...

  4. python3多进程爬虫(第二卷)

    上卷中讲到,我有4个进程,可是我要同时爬取20+数据怎么办,很明显上卷的语法公式不可以,所以现在我引入线程池 现在看一下线程池的语法 看一下爬虫: 注意圈中重点

  5. windows下的tfjs-node安装异常总结

    大约有半年没有写博客了,奔波于上海这座魔都之中.险些忘了自己是个有梦想的全栈工程师 书接上回,由于个人非常厌恶python的语法,半年前发现了tensorflow.js这个宝贝(下简称tfjs),喜出 ...

  6. 教你如何将txt复制到excel的各个单元格;并解决科学计数法显示问题及导致的个位数变0问题

    1.如果你的txt或log等文件中的数据每个数据刚好都回车了,那么直接粘贴到excel即可: 2.如果你的txt或log等文件中数据较多,回车之后的每一行数据仍需再次分列,那么要求:每一行中需要分列的 ...

  7. [VUE]关于路由哪些事儿

    什么是路由 之前有个小伙伴面试被问到:面试官:不用vue能不能写单页面应用?答:用angular啊(咳咳,开个玩笑),答案确实是可以的,原生js中有个事件叫做onhashchange,可以在windo ...

  8. 猫头鹰的深夜翻译:核心JAVA并发一

    简介 从创建以来,JAVA就支持核心的并发概念如线程和锁.这篇文章会帮助从事多线程编程的JAVA开发人员理解核心的并发概念以及如何使用它们. (博主将在其中加上自己的理解以及自己想出的例子作为补充) ...

  9. selenium&appium中的三种等待方式---基于python

    我们在实际使用selenium或者appium时,等待下个等待定位的元素出现,特别是web端加载的过程,都需要用到等待,而等待方式的设置是保证脚本稳定有效运行的一个非常重要的手段,在selenium中 ...

  10. OpenGL Panorama Player

    JMGL_PANO star_war_eve source 1 star_war_eve source 2 1. 介绍 JMGL_PANO 是Justin开源的一个全景视频播放器(Github).基于 ...