Codeforces Round #369 (Div. 2)E
题目:一年有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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #369 (Div. 2) C. Coloring Trees(简单dp)
题目:https://codeforces.com/problemset/problem/711/C 题意:给你n,m,k,代表n个数的序列,有m种颜色可以涂,0代表未涂颜色,其他代表已经涂好了,连着 ...
- 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 ...
- Codeforces Round #369 (Div. 2) D. Directed Roads 数学
D. Directed Roads 题目连接: http://www.codeforces.com/contest/711/problem/D Description ZS the Coder and ...
- Codeforces Round #369 (Div. 2) C. Coloring Trees 动态规划
C. Coloring Trees 题目连接: http://www.codeforces.com/contest/711/problem/C Description ZS the Coder and ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 从CVPR 2014看计算机视觉领域的最新热点
2014看计算机视觉领域的最新热点" title="从CVPR 2014看计算机视觉领域的最新热点"> 编者按:2014年度计算机视觉方向的顶级会议CVPR上月落下 ...
- Python 项目结构
Python 项目结构 实验准备 我们的实验项目名为 factorial. 12 $ mkdir factorial$ cd factorial/ 主代码 我们给将要创建的 Python 模块取名为 ...
- 接口测试-chap5-使用正则表达式提取响应数据
1.导入相关库 import re 2.re.findall(r"前(.+?)后", 匹配源) 3.前:表示要匹配的文本左边的内容 4.后:表示要匹配的文本右边的内容 5.它的返回 ...
- 接口测试-chap3-https请求证书问题
接口地址如果是HTTPS,需要安装证书,或者在发送请求时传入参数verify=False,表示忽略 res = requests.get(url, verify=False)
- Luogu_1080_国王游戏
题目描述 恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这n位大臣排成一排,国王站在队伍的最前面.排好队 ...
- VMWare vCenter 4.x 数据库由SQL Express 迁移至SQL Server 2008 R2
默认安装下的 VMware vCenter 4.x 会在本地安装 SQL Express 2005 版本,如果你有需要迁移至 Full SQL Server版本比如 SQL Server 2008 R ...
- HelloWorld系列(一)- 手把手教你做JDK环境变量配置
分下载,配置,验证三个步骤讲解如何进行JDK环境变量配置. 步骤1:首先看配置成功后的效果步骤2:下载,并解压到E:\JDK步骤3:环境变量配置步骤4:Win10 下环境变量Path的配置步骤5:验证 ...
- 并查集(不相交集)的Union操作
在并查集(不相交集)中附加操作\(Deunion\),它实现的功能是取消最后一次\(Union\)的操作. 实现思想 初始化一个空栈,将每一次的\(Union\)操作的两个集合的根和其值\(Push\ ...
- Ado.net01
------------恢复内容开始------------ 1.ExcuteReader using System; using System.Data.SqlClient; using Syste ...
- Ios/Android h5 唤起本地APP
纠结两天(浏览器中唤起本地APP),一直找不到解决方案,今天总算基本搞定. ps:吐槽一下 魔窗那篇文章,为什么就不直接把js代码开源开源,混淆后的代码看得我好恼火 参考文章:魔窗解决方案.京东解决方 ...