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. Visual Studio通过Cordova支持混合跨平台移动开发

    Microsoft在Visual Studio 2013 Update 2中添加了对混合跨平台移动应用程序的本地支持. Microsoft早在2011年就已经开始了与PhoneGap的合作,那时候是为 ...

  2. 基于Docker 部署Jmeter + Grafana + InfluxDB 性能测试监控配置(亲测可用)

    工具介绍: InfluxDB:是一款用Go语言编写的开源分布式时序.事件和指标数据库,无需外部依赖.该数据库现在主要用于存储涉及大量的时间戳数据,如DevOps监控数据,APP metrics, lo ...

  3. 吴裕雄--天生自然python学习笔记:Python3 模块

    Python3 模块 在前面的几个章节中我们脚本上是用 python 解释器来编程,如果你从 Python 解释器退出再进入,那么你定义的所有的方法和变量就都消失了. 为此 Python 提供了一个办 ...

  4. python 前端技术

    生活中浏览器就是一个客户端,根据搜索内容向不同的服务器发送请求,但是显示最终页面后与请求的服务器断开,想再次看到搜索内容时需要重新连接. 服务端: import socket def handle_r ...

  5. tips [ 18870 ]

    Created at 2017-08-23 Updated at 2018-01-31 Category 东方大陆 Tag 东方大陆 上面有编辑时间的,别吐槽说什么过期内容了使用 lightPIC图床 ...

  6. 实现 add()(1,2)(3,4)(7,8,9)()

    function add(){ var sum=0; function inner(pre,cur){ return pre+cur; } sum=Array.prototype.slice.call ...

  7. SQL命令汇总

    order by rocketmq_id; 查找主从在同一IP的集群和节点2. select rocketmq_id,ip,port,type,count(*) as num  from t_rock ...

  8. Java入门教程一(Java简介)

    什么是Java语言 Java 是由 Sun Microsystems 公司于 1995 年推出的一门面向对象程序设计语言.2010 年 Oracle 公司收购 Sun Microsystems,之后由 ...

  9. 菜鸟系列 Golang 实战 Leetcode —— 面试题24. 反转链表

    定义一个函数,输入一个链表的头节点,反转该链表并输出反转后链表的头节点.   示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3- ...

  10. Slog62_项目上线之ArthurSlog个人网站上线1

    ArthurSlog SLog-62 Year·1 Guangzhou·China September 9th 2018 GitHub NPM Package Page ArthurSlog Page ...