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 ...
随机推荐
- XP停止更新不用愁 瑞星XP护盾给你持续保护
4月8日,微软正式结束了Windows XP的支持,所有XP系统将不会再收到来自微软提供的补丁和安全更新等服务,叱咤OS江湖十几年的一代操作系统终于完美谢幕.但谢幕不等于消失,据相关机构统计,虽然微软 ...
- java生成饼图
pom.xml文件导入依赖包 <!-- https://mvnrepository.com/artifact/org.jfree/jfreechart --> <dependency ...
- Java 并发编程面试题
并发编程面试题-内存模型说下内存模型定义为什么要有内存模型为什么要重排序,重排序在什么时候排如何约束重排序规则happens-before什么是顺序一致性CAS 实现的原理,是阻塞还是非阻塞方式?什么 ...
- django应用的测试
本文章默认用户使用win10系统,并且已经安装pycharm.git.django2.2.5及配套第三方库(python3.6.0及以上版本,且为anaconda环境) 前言 其实在上一期django ...
- js javascript 获取url,获得当前页面的url,静态html文件js读取url参数
获得当前页面的url window.location.href 静态html文件js读取url参数 location.search; //获取url中"?"符后的字串 下边为转载的 ...
- GCD实现多个定时器,完美避过NSTimer的三大缺陷(RunLoop、Thread、Leaks)
定时器在我们每个人做的iOS项目里面必不可少,如登录页面倒计时.支付期限倒计时等等,一般来说使用NSTimer创建定时器: + (NSTimer *)timerWithTimeInterval:(NS ...
- 远程终端协议 TELNET
远程终端协议 TELNET 1.1.概述 TELNET 是一个简单的远程终端协议,也是因特网的正式标准. 用户用 TELNET 就可在其所在地通过 TCP 连接的23端口,使用主机名或 IP 地址登录 ...
- 痞子衡嵌入式:恩智浦i.MX RT1xxx系列MCU启动那些事(11.2)- FlexSPI NOR连接方式大全(RT1060/1064(SIP))
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是恩智浦i.MX RT1060/1064(SIP)两款MCU的FlexSPI NOR启动的连接方式. 上一篇文章<FlexSPI N ...
- Python列表倒序输出及其效率
Python列表倒序输出及其效率 方法一 使用Python内置函数reversed() for i in reversed(arr): pass reversed返回的是迭代器,所以不用担心内存问题. ...
- Linux-基本操作(登入登出,图形化界面,命令行界面)
命令行界面登录 (1)命令行登录界面 安装好Centos后,系统启动默认进入的是图形化界面,可以通过如下命令修改进入命令行界面: 命令行登录:systemctl set-default multi ...