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. Calculation PartⅡ

    GitHub/object-oriented 误删内容--周末修复

  2. 利用Fiddler,解密wireshark抓的HTTPS包

    背景介绍 HTTPS加密方式介绍 浏览器-->SSL Client Hello(我支持这些加密方式)-->服务器 浏览器<-SLL Server Hello(就用这种加密,然后下面是 ...

  3. vector中数据进行去重和排序

    , , , , , , ,}; std::vector<int> vec(a, a+sizeof(a)/sizeof(int) ); std::sort(vec.begin(), vec. ...

  4. Spring Boot 最简单的HelloWorld

    创建一个Spring Boot,可以直接使用构建工具(Maven或Gradle)创建,也可以使用spring.io网站创建,一般会选择使用spring.io创建 使用IDEA创建一个Spring Bo ...

  5. bzoj3676-回文串

    给出一个字符串,一个子串的出现值为字串出现次数乘以长度,求所有回文串中最大的出现值. 分析 回文自动机模版题,建出自动机后直接统计即可. 回文自动机 类似于后缀自动机,不过一条边\((u,v,c)\) ...

  6. 【bzoj3672】[Noi2014]购票 斜率优化dp+CDQ分治+树的点分治

    题目描述  给出一棵以1为根的带边权有根树,对于每个根节点以外的点$v$,如果它与其某个祖先$a$的距离$d$不超过$l_v$,则可以花费$p_vd+q_v$的代价从$v$到$a$.问从每个点到1花费 ...

  7. BZOJ4027 HEOI2015兔子与樱花(贪心)

    首先显然地如果某个点超过了最大负载,删掉它仍然是不合法的.删除某个点当前只会对其父亲产生影响,同一个节点的儿子显然应该按代价从小到大删.考虑如果删掉某个点之后他的父亲不能再删了,我们损失了父亲这个点, ...

  8. css边框以及其他常用样式

    1. 边框是1像素,实体的,红色的. <!DOCTYPE html> <html lang="en"> <head> <meta char ...

  9. 【题解】Atcoder AGC#01 E-BBQ Hard

    计数题萌萌哒~ 这道题其实就是统计 \(\sum_{i=1}^{n}\sum_{j=i+1}^{n}C\binom{a[i] + a[j]}{a[i] + a[j] + b[i] + b[j]}\) ...

  10. 【刷题】BZOJ 3998 [TJOI2015]弦论

    Description 对于一个给定长度为N的字符串,求它的第K小子串是什么. Input 第一行是一个仅由小写英文字母构成的字符串S 第二行为两个整数T和K,T为0则表示不同位置的相同子串算作一个. ...