ZS and The Birthday Paradox

Time Limit: 20 Sec  Memory Limit: 512 MB

Description

  

Input

  

Output

  

Sample Input

  4 3

Sample Output

  23 128

HINT

  

Solution

  

Code

 #include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
using namespace std;
typedef long long s64; const int ONE = ;
const int MOD = 1e6 + ; s64 n, k;
s64 num = ;
s64 Fz = , Fm = ; int get()
{
int res;char c;
while( (c=getchar())< || c> );
res=c-;
while( (c=getchar())>= && c<= )
res=res*+c-;
return res;
} s64 Quickpow(s64 a, s64 b)
{
s64 res = ;
while(b)
{
if(b & ) res = res * a % MOD;
a = a * a % MOD;
b >>= ;
}
return res;
} int main()
{
cin>>n>>k; num = ;
while((1LL << num) < k) num++;
if(num > n) {printf("1 1"); return ;} num = ;
for(s64 i = k - ; i >= ; i >>= )
num += (i >> ); s64 a = Quickpow(, n); Fz = ;
for(int i = ; i < k; i++)
{
Fz = (s64)Fz * (a - i + MOD) % MOD;
if(Fz == ) break;
}
Fm = Quickpow(a, k - ); int inv = Quickpow(Quickpow(, num), MOD - ); Fz = (s64)Fz * inv % MOD, Fm = (s64)Fm * inv % MOD;
Fz = (Fm - Fz + MOD) % MOD; cout<<Fz<<" "<<Fm<<endl;
}

【Codeforces711E】ZS and The Birthday Paradox [数论]的更多相关文章

  1. CF369E. ZS and The Birthday Paradox

    /* cf369E. ZS and The Birthday Paradox http://codeforces.com/contest/711/problem/E 抽屉原理+快速幂+逆元+勒让德定理 ...

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

  3. ZS and The Birthday Paradox

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

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

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

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

  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. c#事件实质

    c#的事件实际上是对windows消息的封装: windows消息系统分为3部分:消息队列,消息循环,窗口过程(wndproc函数)

  2. android入门 — PopupWindow

    第一步:自定义xml文件 第二步:获取LayoutInflater对象 第三步:调用inflate()方法获取View对象 第四步:创建PopupWindow对象 第五步:调用PopupWindow的 ...

  3. python学习笔记02:运行python程序

    1.启动cmd命令行,输入python后回车,运行python解释器: 输入python代码后回车: print('Hello World')

  4. LintCode-41.最大子数组

    最大子数组 给定一个整数数组,找到一个具有最大和的子数组,返回其最大和. 注意事项 子数组最少包含一个数 样例 给出数组[−2,2,−3,4,−1,2,1,−5,3],符合要求的子数组为[4,−1,2 ...

  5. js实现倒计时60秒的简单代码

    <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...

  6. Python实现XML的操作

    本文从以下两个方面, 用Python实现XML的操作: 一. minidom写入XML示例1 二. minidom写入XML示例2 三. ElementTree写入/修改示例 四. ElementTr ...

  7. VBA 实现学校上课教员一学期中所有上课时间,在一页中通过背景底色反应出来

    需求:学校一学期的所有课程表,每个教员都有可能上好几门课,但给一个教员调课时需要查找所调课时间位置有没有此教员上其它的课 相冲突,手动查找很不方便,这里想通过一个表中位置显示出同一教员在所有课表中出现 ...

  8. BZOJ 1057 棋盘制作(最大01相间子矩阵)

    求最大01相间子矩阵可以转换为求最大全0子矩阵.只需把棋盘(x+y)为奇数的取反,而该问题可以用经典的悬线法O(n^2)的求解. 悬线法呢. 首先定义b[i][j],为a[i][j]向上的最大连续0的 ...

  9. 【bzoj5094】硬盘检测 乱搞

    题目描述 已知从 $n$ 个不同的32位无符号整数中随机选 $m=10000$ 次所得的结果,求可能性最大的 $n$ ,其中 $n=10^k,1\le k\le 7$. 输入 第一行包含一个正整数m( ...

  10. 【bzoj2699】更新 dp

    题目描述 对于一个数列A[1..N],一种寻找最大值的方法是:依次枚举A[2]到A[N],如果A[i]比当前的A[1]值要大,那么就令A[1]=A[i],最后A[1]为所求最大值.假设所有数都在范围[ ...