Codeforces 711E ZS and The Birthday Paradox(乘法逆元)
【题目链接】 http://codeforces.com/problemset/problem/711/E
【题目大意】
假设一年有2^n天,问k个小朋友中有两个小朋友生日相同的概率。
假设该概率约分后为 p / q ,输出p , q对1000003取模的解。
【题解】
当k比天数要大时是肯定成立的,否则答案为1-A(2n,k) / (2n)k,
考虑A(2n,k)=2n*(2n-1)*……*(2n-k+1),所以分子和分母的最大公约数是2的幂次,暴力计算分子分母,以及计算最大公约数的逆元,就可以计算出答案。
【代码】
#include <cstdio>
typedef long long ll;
ll n,k;
const ll mod=1000003;
ll pow(ll a,ll b,ll p){ll t=1;for(a%=p;b;b>>=1LL,a=a*a%p)if(b&1LL)t=t*a%p;return t;}
int main(){
scanf("%I64d%I64d",&n,&k);
if(n<=62&&k>1ll<<n){puts("1 1");return 0;}
ll num=0; for(ll i=k-1;i;i>>=1)num+=i/2;
ll b=1,a=pow(2,n,mod);
for(ll i=1;i<=k-1;i++){
ll tmp=(a-i+mod)%mod;
b=b*tmp%mod;
if(!tmp)break;
}ll inv=pow(pow(2,num,mod),mod-2,mod);
a=pow(a,k-1,mod);
a=a*inv%mod; b=b*inv%mod;
b=(a-b+mod)%mod;
printf("%I64d %I64d\n",b,a);
return 0;
}
Codeforces 711E ZS and The Birthday Paradox(乘法逆元)的更多相关文章
- Codeforces 711E ZS and The Birthday Paradox 数学
ZS and The Birthday Paradox 感觉里面有好多技巧.. #include<bits/stdc++.h> #define LL long long #define f ...
- Codeforces 711E ZS and The Birthday Paradox
传送门 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output st ...
- codeforces 711E. ZS and The Birthday Paradox 概率
已知一年365天找23个人有2个人在同一天生日的概率 > 50% 给出n,k ,表示现在一年有2^n天,找k个人,有2个人在同一天生日的概率,求出来的概率是a/b形式,化到最简形式,由于a,b可 ...
- Codeforces 543D Road Improvement(树形DP + 乘法逆元)
题目大概说给一棵树,树的边一开始都是损坏的,要修复一些边,修复完后要满足各个点到根的路径上最多只有一条坏的边,现在以各个点为根分别求出修复边的方案数,其结果模1000000007. 不难联想到这题和H ...
- 【28.57%】【codeforces 711E】ZS and The Birthday Paradox
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- codeforces 711E E. ZS and The Birthday Paradox(数学+概率)
题目链接: E. ZS and The Birthday Paradox. time limit per test 2 seconds memory limit per test 256 megaby ...
- 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 ...
- ZS and The Birthday Paradox
ZS and The Birthday Paradox 题目链接:http://codeforces.com/contest/711/problem/E 数学题(Legendre's formula) ...
- CF369E. ZS and The Birthday Paradox
/* cf369E. ZS and The Birthday Paradox http://codeforces.com/contest/711/problem/E 抽屉原理+快速幂+逆元+勒让德定理 ...
随机推荐
- RabbitMQ 消息队列
一:简介 RabbitMQ是一个在AMQP协议标准基础上完整的,可服用的企业消息系统.他遵循Mozilla Public License开源协议.采用 Erlang 实现的工业级的消息队列(MQ)服务 ...
- OSC本地库推送到远程库
1.新建远程库: 例如:http://git.oschina.net/intval/learngit 2.本地生成ssh密钥 ssh-keygen -t rsa -C "intval@163 ...
- oracle 取头十条数据
select * from(select * from table order by age)where rownum < 11
- mysql模糊匹配
select * from tableName where column like ""; select * from tableName where column regexp ...
- [原创]使用GCC创建 Windows NT 下的内核DLL
原文链接:使用GCC创建 Windows NT 下的内核DLL 在温习<<Windows 2000 Driving>>分层驱动程序一章的时候,看到了关于紧耦合驱动连接方式,这种 ...
- 初识Sencha Touch:面板Panel
HTML代码: <!doctype html> <html> <head> <meta charset="utf-8"> <t ...
- sp<> 强指针类的用法
在android 中可以广泛看到的template<typename T>, class Sp 句柄类实际上是android 为实现垃圾回收机制的智能指针.智能指针是c++ 中的一个概念 ...
- Android SQLiteDatabase使用总结
SQLiteDatabase数据库操作 1.创建一个继承了类SQLiteOPenHelper类复写相应的方法,和构造函数 2.然后创建一个类,定义一个私有变量(上述类的实例化对象),在构造函数中进行初 ...
- 继承ViewGroup研究(汇总) 一、二、三
转载过来:为一.二.三版本. 仅供参考: 继承ViewGroup研究(1) --简介和一个小Demo 又翻开一个新篇章了,哈哈,上一回学习的是继承View,关于继承View个人感觉不是那么完美,做技术 ...
- [Leetcode][Python]26: Remove Duplicates from Sorted Array
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 26: Remove Duplicates from Sorted Array ...