CodeForces 369 div2 E. ZS and The Birthday Paradox 数论

解压密码获取器1.3.4. 解压密码获取器1.3.4. 解压密码获取器1.3.4. 立即下载

E. ZS and The Birthday Paradox
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and decides to test this with the inhabitants of Udayland.

In Udayland, there are 2n days in a year. ZS the Coder wants to interview k people from Udayland, each of them has birthday in one of 2ndays (each day with equal probability). He is interested in the probability of at least two of them have the birthday at the same day.

ZS the Coder knows that the answer can be written as an irreducible fraction . He wants to find the values of A and B (he does not like to deal with floating point numbers). Can you help him?

Input

The first and only line of the input contains two integers n and k (1 ≤ n ≤ 1018, 2 ≤ k ≤ 1018), meaning that there are 2n days in a year and that ZS the Coder wants to interview exactly k people.

Output

If the probability of at least two k people having the same birthday in 2n days long year equals  (A ≥ 0, B ≥ 1, ), print the A and B in a single line.

Since these numbers may be too large, print them modulo 106 + 3. Note that A and B must be coprime before their remainders modulo106 + 3 are taken.

Examples
input
3 2
output
1 8
input
1 3
output
1 1
input
4 3
output
23 128
Note

In the first sample case, there are 23 = 8 days in Udayland. The probability that 2 people have the same birthday among 2 people is clearly, so A = 1, B = 8.

In the second sample case, there are only 21 = 2 days in Udayland, but there are 3 people, so it is guaranteed that two of them have the same birthday. Thus, the probability is 1 and A = B = 1.


题意:

有2^n天,k个人,求至少2个人生日相同的概率,要求分子分母约分后再对1e6+3取模。

思路“:

1.如果人数比天数多了那就一定有至少2个人是同一天的。

2.算反面,所有人生日都不同,那么第一个人的可能是2^n/2^n,第二个人是(2^n-1)/2^n...第k个人是(2^n-(k-1))/2^n.

所以反面是  

我们要算的是f(n,k) = 1-,然后gcd(a,b) = gcd(b-a,b)  所以f(n,k)要约的数和这个表达式是一样的,考虑到分母是2的指数,所以我们要求分子能提出几个2,然后就可以解决了。还有一个问题是,k很大,那分母的一串乘积怎么办呢,我们注意到mod很小,而且这串积是连续的数,所以当某一个是mod的倍数,那我们就不用接着算了。


代码:

//************************************************************************//
//*Author : Handsome How                                                 *//
//************************************************************************//
//#pragma comment(linker, "/STA    CK:1024000000,1024000000")
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define foreach(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define fur(i,a,b) for(int i=(a);i<=(b);i++)
#define furr(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#ifdef HandsomeHow
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define dbg(x) cout << #x << " = " << x << endl
#else
#define debug(...)
#define dbg(x)
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const ll mod=1000003;
const double pi=acos(-1);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){a%=mod;ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★
//-----------------------------------------------------------------
ll n,k;
int main(){
#ifdef HandsomeHow
    //freopen("data.in","r",stdin);
    //freopen("data.out","w",stdout);
    time_t beginttt = clock();
#endif
	cin>>n>>k;
	if(n<=60 && k>(1ll<<n))
	return 0*printf("1 1\n");//人比天数多 
	ll t = k;
	ll ys = 0ll;
	ll d = powmod(2,n,mod);//2^n
	--t;
	ll now = 2ll;
	while(now<=t){
		ys += (t/now);		//分子含2的个数 
		now<<=1;
	}
	ll ny = powmod(2ll,mod-2ll,mod);//2关于mod的逆元 
	ll fz = 1, fm = 1;
	fur(i,2,k){
		fz = fz * (d-i+1) % mod;
		if(fz == 0) break;
	}
	fz = fz * powmod(ny,ys,mod) % mod;
	fm = powmod(2ll,n,mod);
	fm = powmod(fm,k-1,mod);
	fm = fm * powmod(ny,ys,mod) % mod;
	fz = fm - fz;
	if(fz<0) fz+=mod;
	printf("%I64d %I64d\n",fz,fm);
#ifdef HandsomeHow
	time_t endttt = clock();
    debug("time: %d\n",(int)(endttt - beginttt));
#endif
	return 0;
}



2018常用密码top100 top100常用密码。 立即下载

相关推荐

Setup-Fluxay5(解压密码xzb)

流光扫描器安装包

CodeForces-711E ZS and The Birthday Paradox(勒让德定理+抽屉原理)

E. ZS and The Birthday Paradox time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder has recently fo

十分残念的博客 694

开源机器学习平台tipdm

TipDM建模平台 tipdm开源的python机器学习建模平台,用户通过拖拉就可以实现模型开发。 项目结构 backend :为java后台服务代码 frontedn :为vue js前端代码 mock-oauth-server:为java认证服务代码 主要分析backend后台服务代码,典型的java spring mvc web项目,项目结构如下: framework-common:公共代码,主要为工具类,spring相关公用类 framework-model: 实体..

wflh323的专栏 4252

[Codeforces #369 (Div. 2)E. ZS and The Birthday Paradox]勒让德定理+逆元

[Codeforces #369 (Div. 2)E. ZS and The Birthday Paradox]勒让德定理+逆元题目链接:[Codeforces #369 (Div. 2)E. ZS and The Birthday Paradox] 题意描述:这个题目是基于生日悖论为背景的一道题目。某个星球一年有2N2^N天,有K个人,问存在两个或两个以上的人同一天生日的概率,要求写成约分之后的

Fighting! 1216

数字孪生实战:如何用Blender+Unity快速搭建未来工厂3D模型(附资源包)

本文提供了一套利用Blender进行三维建模,再结合Unity构建虚拟仿真环境的实用方案,旨在帮助中小型制造企业低成本、高效率地搭建未来工厂数字孪生原型系统。文章详细介绍了从数据规划、模型优化到场景构建、逻辑仿真与数据对接的全流程,并附有资源包,助力技术团队快速实现从静态展示到动态交互的数字孪生应用。

weixin_29191669的博客 352

c++实现异步线程池并详细分析线程池析构流程

多线程编程是提高程序性能和响应能力的关键技术之一,异步线程池作为多线程编程的一种有效实现方式,能够管理和复用线程资源,避免频繁创建和销毁线程带来的开销。在本文中,我们将深入探讨如何实现一个异步线程池。

2301_76564925的博客 1602

Codeforces 711E ZS and The Birthday Paradox

E. ZS and The Birthday Paradox time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder has recently fo

nare123的博客 485

[SVA]SystemVerilog Assertion Property开发技巧总结

SystemVerilog Assertion开发技巧总结 一、在property中可以使用if-else条件语句 如下面的例子,根据misc_phy_12g_rx的取值,选择不同的判断语句 property ck1_en_rose_chk(); @(posedge clk) disable iff(~rst_n) ad_pn_ck1en & (current_state !== ST_IDLE) |->...

元直的博客 5930

Codeforces711 E. ZS and The Birthday Paradox(数论)

题意: 解法: 当k>2n时,显然概率=1,下面只考虑k<=2n的情况.容易想到将问题转化为1−(k个人生日互不相同的概率).k个人生日互不相同的概率=A(2n,k)2nk=∏i=2n−k+12ni2nk=∏i=2n−k+12n−1i2n(k−1)分母可以直接快速幂.对于分子部分,由于需要对1e6+3取模,那么当分子存在1e6+3时,取模就会变成0,观察到分子的区间为[2n−1−k+1,2n−1],区间长度=k−1,当k−1>=1e6+3时,一定存在一个1e6+3的倍数,当k−1<

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 311

物联网竞赛单片机应用开发-项目汇总

物联网竞赛单片机应用开发-项目汇总

a6662580的博客 9010

TC8:IPv4_HEADER_05-09

所有主机都必须准备好接受最多576个字节的数据报我们知道最大传输单元MTU通常是1500个字节,也就是说一条IP数据报的Header+payload最大1500,那为什么这条测试用例又要求主机准备好接受最多576个字节的IP数据报呢。

jasonj333 525

【28.57%】【codeforces 711E】ZS and The Birthday Paradox

time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output ZS the Coder has recently found an interesting concept called the Birthday P...

239

接口电路设计的关键要点

接口电路设计是嵌入式硬件开发的核心环节,本文系统阐述了五大关键设计要点:1)电平匹配技术,详细分析了3.3V/5V系统互连方案及转换电路计算;2)阻抗匹配原理,包括高速信号反射机制及差分信号处理;3)滤波与去耦设计,提出多级电容配置和"先电容后过孔"布局原则;4)接地设计规范,重点说明模拟/数字地分离及高速信号回流路径;5)防护电路设计,涵盖防反接、过流保护及ESD防护方案。文章通过具体计算公式、器件选型指南和布局技巧,为接口电路设计提供了系统化的解决方案,并附有设计检查清单和典型问题分

weiyvyy的博客 459

codeforces Round#369 div2-E ZS and The Birthday Paradox(逆元,组合)★

题意: 一年中有2^n天,问有k个人至少有两个人生日在同一天的概率,用分数表示。其中n,k 题解:1e6+3为素数。直接求不好求,我们可以总数-不成立的数。不成立的即为k个人中没有一个人的生日在同一天,即。而当k-1>=mod时,分子中必然含有mod的倍数,取余后分子为0;当k-1 由于分母中只含素数2,化简时只需求出分子中2的个数。然后乘上它的逆元就好 注意:k>2^n的情况,

Ezereal的博客 1318

华为OD机试 - 第k个排列 - 全排列递归(Python/JS/C/C++ 2025 C卷 100分)

给定参数n,从1到n会有n个整数:1,2,3,…,n,这n个数字共有n!按大小顺序升序列出所有排列的情况,并一一标记当n=3时,所有排列如下“123”,“132,“213”,“231”,“312”,“321”输入两行,第一行为n,第二行为k,给定n的范围是[1,9],给定k的范围是[1,n!排列为“12”和“21”,第2个是“21”。给定n和k,返回第k个排列。输出排在第k位置的数字。只有一个排列,直接返回。

学Java,找哪吒 999

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

codeforces Round#369 div2-E ZS and The Birthday Paradox

题意: 一年中有2^n天,问有k个人至少有两个人生日在同一天的概率,用分数表示。其中n,k 题解:1e6+3为素数。直接求不好求,我们可以总数-不成立的数。不成立的即为k个人中没有一个人的生日在同一天,即。而当k-1>=mod时,分子中必然含有mod的倍数,取余后分子为0;当k-1 由于分母中只含素数2,化简时只需求出分子中2的个数。 注意:k>2^n的情况,直接输出1 1即可 #incl

MustImproved的博客 711

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Codeforces 711 E. ZS and The Birthday Paradox(数学)——Codeforces Round #369 (Div. 2)

[传送门](http://codeforces.com/contest/711/problem/E) E. ZS and The Birthday Paradoxtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputZS the Coder has r

代码改变世界 1585

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

Codeforces #369 (Div. 2) E. ZS and The Birthday Paradox (勒让德定理+逆元)

E. ZS and The Birthday Paradox time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder has recently fo

LzyRapX 906

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 the Coder has recently found an interesting concept called the Birthday Paradox. It states that give...

weixin_30649641的博客 108

Codeforces Problem 711E ZS and The Birthday Paradox(抽屉原理+乘法逆元+费马小定理+组合数+快速幂+概率论)

Codeforces Problem 711E ZS and The Birthday Paradox(抽屉原理+乘法逆元+费马小定理+组合数+快速幂+概率论)

queuelovestack的专栏 1411

[Codeforces 711E] ZS and The Birthday Paradox (数学+Legendre公式)

Codeforces - 711E 生日攻击的模型,现在有 2^n天,k个人,问不冲突的概率 其中 n和 k都是在 LL范围内的数,并且要输出既约分数 很容易就列出计算式,难点就在于约分 算式大概是 1−ab=b−ab1-\frac a b = \frac {b-a} b这个形式的 然后可得 gcd(b−a,b)=gcd(a,b)\gcd(b-a, b) = \gcd(a, b) 所

MisDeer's blog 436

ZS and The Birthday Paradox

ZS and The Birthday Paradox 题目链接:http://codeforces.com/contest/711/problem/E 数学题(Legendre's formula) 这题是以生日悖论(如果有23个或23个以上的人,那么至少有两个人的生日相同的概率要大于50%)为背景的数学题。公式本身不难推,主要是对大数的处理。 首先,我们需要找到分子和分母的公因数,这里...

weixin_33842328的博客 176

Light oj 1104 Birthday Paradox (生日悖论----概率)

已知星球上有多少天,问至少邀请多少人参加生日party能使party上至少两个人 同一天生日的概率至少为0.5。 算法: 就是概率公式。参看wiki:生日悖论  计算机率的方法是,首先找出p(n)表示n个人中,每个人的生日日期都不同的概率。假如n > 365,根据鸽巢原理其概率为0,假设n ≤ 365,则概率为:      因为第二个人不能跟第一个人有相同的

虽然冲动永远比坚持容易~ 2644

CF369E. ZS and The Birthday Paradox

1 /* 2 cf369E. ZS and The Birthday Paradox 3 http://codeforces.com/contest/711/problem/E 4 抽屉原理+快速幂+逆元+勒让德定理+费马小定理+欧拉定理+数论 5 题解:https://amoshyc.github.io/ojsolution-build/cf/cf369/pe.h...

dianan9456的博客 241

CodeForces711E ZS and The Birthday Paradox 费马小定理求逆元

ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birt

Megumin的博客 839
上一篇: CodeForces 369 div2 D Directed Roads 图论 数论
下一篇: codeforces 709 D Recover the String (构造)
HandsomeHow
博客等级 码龄11年 5粉丝 55原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值