/*
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的更多相关文章

  1. 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 ...

  2. ZS and The Birthday Paradox

    ZS and The Birthday Paradox 题目链接:http://codeforces.com/contest/711/problem/E 数学题(Legendre's formula) ...

  3. Codeforces 711E ZS and The Birthday Paradox 数学

    ZS and The Birthday Paradox 感觉里面有好多技巧.. #include<bits/stdc++.h> #define LL long long #define f ...

  4. 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 ...

  5. 【Codeforces711E】ZS and The Birthday Paradox [数论]

    ZS and The Birthday Paradox Time Limit: 20 Sec  Memory Limit: 512 MB Description Input Output Sample ...

  6. Codeforces 711E ZS and The Birthday Paradox

    传送门 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output st ...

  7. cf711E ZS and The Birthday Paradox

    ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that g ...

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

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. codeforces 711E. ZS and The Birthday Paradox 概率

    已知一年365天找23个人有2个人在同一天生日的概率 > 50% 给出n,k ,表示现在一年有2^n天,找k个人,有2个人在同一天生日的概率,求出来的概率是a/b形式,化到最简形式,由于a,b可 ...

随机推荐

  1. struts1——静态ActionForm与动态ActionForm

    在struts1中,我们能够使用ActionForm来获取从client端提交上来的数据.并通过action配置中的name属性.将某个ActionForm配置到某次请求应答的Action中.作为本次 ...

  2. leetcode解题文件夹

    点击打开链接点击打开链接点击打开链接參考文献:http://blog.csdn.net/lanxu_yy/article/details/17848219 只是本文准备用超链接的方式连接到对应解答页面 ...

  3. 求int型数据在内存中存储时1的个数

    1.求int型数据在内存中存储时1的个数 输入一个int型数据,计算出该int型数据在内存中存储时1的个数. 我们非常easy想到例如以下方法: #include <iostream> u ...

  4. UVA 1201 - Taxi Cab Scheme(二分图匹配+最小路径覆盖)

    UVA 1201 - Taxi Cab Scheme 题目链接 题意:给定一些乘客.每一个乘客须要一个出租车,有一个起始时刻,起点,终点,行走路程为曼哈顿距离,每辆出租车必须在乘客一分钟之前到达.问最 ...

  5. AIX的系统备份

    AIX克隆盘即AIX的rootvg的备用替换磁盘,用于保留AIX的原始状态,它可作为软件的升级后出现问题快速回退到原系统的备份手段,也可用于测试两个不同版本的AIX系统.系统可保留两块引导磁盘,而且都 ...

  6. 微信小程序蓝牙连接小票打印机

    1.连接蓝牙 (第一次发表博客)   第一步打开蓝牙并搜索附近打印机设备// startSearch: function() { var that = this wx.openBluetoothAda ...

  7. JS——BOM操作(基本用法与实现:open()、close()、scrollTop等了解)

    (1)window.open() 定义和用法 open() 方法用于打开一个新的浏览器窗口或查找一个已命名的窗口 语法 window.open(URL,name,specs,replace) [默认填 ...

  8. pythonOCC版 瓶子代码

    #!/usr/bin/env python # -*- coding:utf-8 -*- ##Copyright 2009-2015 Thomas Paviot (tpaviot@gmail.com) ...

  9. 第7章 性能和可靠性模式 Server Clustering(服务器群集)

    上下文 您正在设计要部署应用程序的基础结构层.运行要求包括无法满足的可用性或性能能力,因为基础结构中存在性能瓶颈或故障单点. 影响因素 设计基础结构时,请考虑下列影响因素: 用户希望在使用应用程序时这 ...

  10. React安装 脚手架create-react-app安装步骤及问题

    create-react-app 是来自于 Facebook的脚手架,通过该命令我们无需配置就能快速构建 React 开发环境. 安装步骤: 1.先装脚手架     PS:第一次装直接在打开CMD默认 ...