CF369E. ZS and The Birthday Paradox
/*
cf369E. ZS and The Birthday Paradox
http://codeforces.com/contest/711/problem/E
抽屉原理+快速幂+逆元+勒让德定理+费马小定理+欧拉定理+数论
题解:https://amoshyc.github.io/ojsolution-build/cf/cf369/pe.html 坑点:
1、long long 类型的常量一定要加LL,否则1<<n只在int范围内
2、带模的题目,最后一定要判断是否答案为负,答案为负数要加mod
*/
#include <cstdio>
#include <algorithm>
using namespace std;
const int mod=;
long long n,k;
long long Legendre(long long n,long long p)//勒让德定理:O(logn) 算出n!中有多少个p
{
long long ans=;
while(n>)
{
ans+=n/p;
n/=p;
}
return ans;
}
long long pow(long long base,long long n)
{
long long ans=;
base=base%mod;//先取模防止爆long long
while(n>)
{
if(n&)
ans=(ans*base)%mod;
base=(base*base)%mod;
n>>=;
}
return ans;
}
int main()
{
//freopen("cf711E.in","r",stdin);
scanf("%I64d%I64d",&n,&k);
if(n<= && k>(1LL<<n))//抽屉原理
{
printf("1 1\n");
return ;
}
long long gcd=Legendre(k-,);
long long p=,q;//p/q;
q=((n%(mod-))*((k-)%(mod-))-gcd%(mod-))%(mod-)+mod-;//欧拉函数降幂
//q=(n%(mod-1))*((k-1)%(mod-1))+mod-1-gcd; this is a wrong way!!!!!!
q=pow(,q)%mod;//q=2^( n(k-1)-gcd ) <=> 2^((n(k-1)-gcd)%phi(mod)+phi(mod) );
if(k->=mod)//抽屉原理得出在分子中必定存在一个%mod=0,标程大坑,不能直接输出1 1,即此处不约分。
p=;
else
{
long long val=pow(,n);
for(long long i=;i<=k-;i++)
{
p=(p*((val-i))%mod)%mod;
}
if(gcd)
{
p=(p*pow(pow(,gcd),mod-))%mod;
//p=(p+mod)/pow(2,gcd);
}
}
p=q-p;
if(p<)//判断是否为负
p+=mod;
printf("%I64d %I64d\n",p,q);
return ;
}
CF369E. ZS and The Birthday Paradox的更多相关文章
- 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 ...
- ZS and The Birthday Paradox
ZS and The Birthday Paradox 题目链接:http://codeforces.com/contest/711/problem/E 数学题(Legendre's formula) ...
- Codeforces 711E ZS and The Birthday Paradox 数学
ZS and The Birthday Paradox 感觉里面有好多技巧.. #include<bits/stdc++.h> #define LL long long #define f ...
- 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 ...
- 【Codeforces711E】ZS and The Birthday Paradox [数论]
ZS and The Birthday Paradox Time Limit: 20 Sec Memory Limit: 512 MB Description Input Output Sample ...
- Codeforces 711E ZS and The Birthday Paradox
传送门 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output st ...
- cf711E ZS and The Birthday Paradox
ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that g ...
- 【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. ZS and The Birthday Paradox 概率
已知一年365天找23个人有2个人在同一天生日的概率 > 50% 给出n,k ,表示现在一年有2^n天,找k个人,有2个人在同一天生日的概率,求出来的概率是a/b形式,化到最简形式,由于a,b可 ...
随机推荐
- Flip Game(枚举)Poj
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31329 Accepted: 13622 De ...
- OC中使用UI自己定义控件实现计算器的设计(版本号1简单的加减乘除,连加,连减,连除,连乘)
OC中使用UI自己定义控件实现计算器的设计(版本号1简单的加减乘除,连加.连减,连除,连乘) #import <UIKit/UIKit.h> @interface ViewControll ...
- 实战c++中的string系列--CDuiString和string的转换(duilib中的cduistring)
使用所duilib的人定会知道cduistring类型,先看看这个类是怎么定义的: class UILIB_API CDuiString { public: enum { MAX_LOCAL_STRI ...
- c++迭代器失效问题
参考两篇文章:https://blog.csdn.net/skyroben/article/details/70877008 https://lichanghao.github.io/2016/08/ ...
- bzoj2819: Nim(博弈+树剖)
2819: Nim 题目:传送门 题解: 很久之前学博弈的时候看过的一道水题,其实算不上博弈吧... 直接套上一个裸的树剖啊,把路径上的点值全都xor(xor满足结合率所以就不管那么多随便搞啦) do ...
- Swift-理解值类型
在这里,我们要讲讲值类型和写时复制.在 swift 的标准库中,所有的集合类型都使用了写时复制.我们在本篇文章中看一下写时复制如何工作的,并且如何实现它. 引用类型 使用 swift 的 Data 和 ...
- IPv6通讯原理(1) - 不能忽略的网卡启动过程
本文主题:通过抓包分析,深入观察网卡启动过程的每个步骤,从而逐步掌握通讯原理.
- SDL2源代码分析
1:初始化(SDL_Init()) SDL简介 有关SDL的简介在<最简单的视音频播放示例7:SDL2播放RGB/YUV>以及<最简单的视音频播放示例9:SDL2播放PCM>中 ...
- ReactiveX
http://reactivex.io The real power comes with the “reactive extensions” (hence “ReactiveX”) — operat ...
- 应用七:Vue之适配test环境变量(2.0版)
在我们使用vue-cli创建的项目中,默认只有开发development和生产production两种环境变量:但在实际的项目开发过程中往往都会有测试环境,下面就来说一下如何适配测试环境test的环境 ...