当前位置: 首页 > news >正文

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 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 of2n days (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

题意:

一年有2^n天,现在有k个熊孩子,问至少有两个熊孩子的生日是同一天的概率是多少;

思路:

1-2^n*(2^n-1)*...*(2^n-k+1)/(2^n)^k,然后就是求gcd了,约分后再求逆元,反正这个题涉及的知识点有概率论与组合数学,抽屉原理,勒让德定理,求逆元,快速幂这些,反正我是看别人代码才会的,我好菜啊;

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map>
 
using namespace std;
 
#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
 
typedef  long long LL;
 
template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
    for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
    F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
    if(!p) { puts("0"); return; }
    while(p) stk[++ tp] = p%10, p/=10;
    while(tp) putchar(stk[tp--] + '0');
    putchar('\n');
}
 
const LL mod=1e6+3;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=2e5+10;
const int maxn=1e3+520;
const double eps=1e-12;

LL n,k;

int check()
{
    LL s=1;
    for(int i=1;i<=n;i++)
    {
        s=s*2;
        if(s>=k)return 0;
    }
    return 1;
}
LL pow_mod(LL x,LL y)
{
    LL s=1,base=x;
    while(y)
    {
        if(y&1)s=s*base%mod;
        base=base*base%mod;
        y>>=1;
    }
    return s;
}
int main()
{
    read(n);read(k);
    if(check()){cout<<"1 1\n";return 0;}
    LL num=0;
    for(LL i=k-1;i>0;i/=2)num+=i/2;
    LL temp=pow_mod(2,n),ans=1;
    for(LL i=1;i<k;i++)
    {
        ans=ans*(temp-i)%mod;
        if(temp-i==0)break;
    }
    LL ha=pow_mod(2,num);
    ans=ans*pow_mod(ha,mod-2)%mod;
    temp=pow_mod(temp,k-1)*pow_mod(ha,mod-2)%mod;
    cout<<(temp-ans+mod)%mod<<" "<<temp<<endl;


    return 0;
}

  

转载于:https://www.cnblogs.com/zhangchengc919/p/5826361.html

相关文章:

  • java解惑你知多少(七)
  • css3 TransformZ() 3D缩放
  • java解惑你知多少(八)
  • 多线程总结之旅(8):线程同步之信号量
  • java类初始化顺序
  • bootstrap总结
  • java创建对象的四种方式
  • java基础之String
  • 为什么单例对象的并发调用需要同步?
  • Spring_事务(1)
  • java集合框架总结
  • LeetCode-Count Bits
  • Java中对HashMap的深度分析与比较
  • java 线程小结
  • JAVA中精确计算金额BigDecimal
  • 30秒的PHP代码片段(1)数组 - Array
  • Codepen 每日精选(2018-3-25)
  • CSS相对定位
  • github指令
  • iOS 系统授权开发
  • Mysql优化
  • NSTimer学习笔记
  • oldjun 检测网站的经验
  • SegmentFault 2015 Top Rank
  • sessionStorage和localStorage
  • SSH 免密登录
  • webpack入门学习手记(二)
  • 互联网大裁员:Java程序员失工作,焉知不能进ali?
  • 快速体验 Sentinel 集群限流功能,只需简单几步
  • 浏览器缓存机制分析
  • 如何用vue打造一个移动端音乐播放器
  • 阿里云ACE认证学习知识点梳理
  • ​ 无限可能性的探索:Amazon Lightsail轻量应用服务器引领数字化时代创新发展
  • #我与Java虚拟机的故事#连载09:面试大厂逃不过的JVM
  • $.ajax中的eval及dataType
  • (2009.11版)《网络管理员考试 考前冲刺预测卷及考点解析》复习重点
  • (C#)Windows Shell 外壳编程系列4 - 上下文菜单(iContextMenu)(二)嵌入菜单和执行命令...
  • (C语言版)链表(三)——实现双向链表创建、删除、插入、释放内存等简单操作...
  • (Mac上)使用Python进行matplotlib 画图时,中文显示不出来
  • (Matlab)基于蝙蝠算法实现电力系统经济调度
  • (webRTC、RecordRTC):navigator.mediaDevices undefined
  • (附源码)springboot 智能停车场系统 毕业设计065415
  • (过滤器)Filter和(监听器)listener
  • (强烈推荐)移动端音视频从零到上手(下)
  • (新)网络工程师考点串讲与真题详解
  • (一)SpringBoot3---尚硅谷总结
  • (一)使用IDEA创建Maven项目和Maven使用入门(配图详解)
  • (转)视频码率,帧率和分辨率的联系与区别
  • ***监测系统的构建(chkrootkit )
  • .bat批处理(三):变量声明、设置、拼接、截取
  • .bat批处理(一):@echo off
  • .NET CORE 3.1 集成JWT鉴权和授权2
  • .NET Core工程编译事件$(TargetDir)变量为空引发的思考
  • .Net 中Partitioner static与dynamic的性能对比
  • .NET 中选择合适的文件打开模式(CreateNew, Create, Open, OpenOrCreate, Truncate, Append)