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 抽屉原理+快速幂+逆元+勒让德定理 ...
随机推荐
- CGI version1.1-第一章 介绍 (译)
CGI version1.1-第一章 介绍 1.简介 1.1 用途 CGI 是为 HTTP服务器 与 CGI脚本 在 响应客户端请求分配职责, 客户请求由url,方法与关于传输协议的附属信息, CGI ...
- ubuntu中Mysql常用命令整理
启动mysql服务sudo /etc/init.d/mysql start 关闭mysql服务sudo /etc/init.d/mysql stop
- 构造HTTP请求Header实现"伪造来源IP"
构造 HTTP请求 Header 实现“伪造来源 IP ” 在阅读本文前,大家要有一个概念,在实现正常的TCP/IP 双方通信情况下,是无法伪造来源 IP 的,也就是说,在 TCP/IP 协议中,可以 ...
- 工作备份 build.gradle
apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion '22.0.0' de ...
- laravel post请求失败
今天继续研究laravel,在路由里注册了一个控制器路由Route::controller(). 先get请求一个页面 class UserController extends Controller{ ...
- mud目录命令说明
目錄結構 以下列出的是 ES2 mudlib 根目錄下標準的子目錄結構,以及簡短的說明. /adm 儲存由系統管理者所管理的程式與資料檔. /std 儲存標準物件的程式碼. /obj 儲存通用物件 ...
- pickle模块
在编程中,如果存在大的列表或者字典,可以在python中引入pickle 模块: 例如:将下边这组列表保存到文件当中:[1, 2, 'xiaomao', '小狗'] 程序: import pickle ...
- SingleNumber python实现
Single Number Given an array of integers, every element appears twice except for one. Find that sing ...
- (9)Xamarin测试账号申请与续用
原文 Xamarin测试账号申请与续用 在Xamarin网站上可以申请30天试用的测试账号.试用期内,Xamarin会提供完整的功能试用. 30天试用时间到期后,在Visual Studio里面你加载 ...
- 从零开始学 iOS 开发的15条建议
事情困难是事实,再困难的事还是要每天努力去做是更大的事实. 因为我是一路自学过来的,并且公认没什么天赋的前提下,进步得不算太慢,所以有很多打算从零开始的朋友会问我,该怎么学iOS开发.跟粉丝群的朋友交 ...