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可 ...
随机推荐
- matlab实现基于DFS的Ford_Fulkerson最大流最小割算法
function [F, maxf, V, S] = Ford_Fulkerson(C, src, sink) n = size(C, 1); F = zeros(n); maxf = 0; V = ...
- QString够绕的,分为存储(编译器)和解码(运行期),还有VS编译器的自作主张,还有QT5的变化
多读几篇,每篇取几句精华加深我对QString的理解. ------------------------------------------------------------------ QStri ...
- 如何删除github wiki page
title: 如何删除github wiki page toc: false date: 2019-02-23 10:08:41 categories: methods tags: github wi ...
- 9.13[XJOI] NOIP训练32
今日9.13 洛谷打卡:小吉(今天心情不错,决定取消密码) (日常记流水账) 上午 今天听说是鏼鏼的题目,题面非常的清真啊,也没有当初以为的爆零啊 T1 排排坐 非常非常清真的模拟或是结论题,再次将难 ...
- Docker 内部之间的网络连接
一.简介 内部网络连接的2中方式: Docker NetWorking (1.9版本之后推荐使用这个)和 Docker link(1.9 版本之前都使用这个) 推荐使用docker networkin ...
- CI中的url相关函数以及路由设置和伪静态技术
当使用CI框架进行开发时,我们的一些数据传递的URL不应该写死,可以使用如下方法:比如说我们需要表单提交一个数据: 1.在controller控制器中我们需要先创建一个加载helper和视图的方法: ...
- BZOJ1222: [HNOI2001]产品加工(诡异背包dp)
Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 907 Solved: 587[Submit][Status][Discuss] Descriptio ...
- P1284 三角形牧场
题目描述 和所有人一样,奶牛喜欢变化.它们正在设想新造型的牧场.奶牛建筑师Hei想建造围有漂亮白色栅栏的三角形牧场.她拥有N(3≤N≤40)块木板,每块的长度Li(1≤Li≤40)都是整数,她想用所有 ...
- 对比JavaScript的入口函数和jQuery的入口函数
JavaScript的入口函数要等到页面中所有的资源(包括图片.文件)加载完成才开始执行. jQuery的入口函数只会等待文档数加载完成就开始执行,并不会等待图片.文件的加载.
- 当接口上配了 FeignClient 和 RequestMapping 两个注解,结果错误提示 重复mapping处理方法
再接手老文档的时候,发现有这么一个问题 错误显示为: 原文档写法: 解决方法: 这是一个编译时写法的问题,将上方的RequestMapping去掉,然后把路径放在下面的PostMapping 便可以正 ...