CodeForces 711 E.ZS and The Birthday Paradox(组合数学)
来源:互联网 发布:linux用户加组 编辑:程序博客网 时间:2024/05/17 01:59
Description
一年2^n天,k个人,问这k个人中至少有两个人生日是同一天的概率
Input
两个整数n和k(1<=n<=1e18,2<=k<=1e18)
Output
将答案表示为最简分数形式A/B,输出A B,结果过大把A和B模1e6+3后输出
Sample Input
3 2
Sample Output
1 8
Solution
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 1111const ll mod=1000003;ll mod_pow(ll a,ll b,ll c){ ll ans=1; while(b) { if(b&1)ans=ans*a%c; a=a*a%c; b>>=1; } return ans;}ll Count(ll k){ ll ans=0; while(k)ans+=k/2,k/=2; return ans;}int main(){ ll n,k; while(~scanf("%I64d%I64d",&n,&k)) { int kk=0; while((1ll<<kk)<k)kk++; if(kk>n) { printf("1 1\n"); continue; } ll num=Count(k-1),a=mod_pow(2,n%(mod-1),mod),b=mod_pow(2,mod-1-num%(mod-1),mod); ll ans1=mod_pow(a,k-1,mod)*b%mod; if(k-1>=mod)printf("%I64d %I64d\n",ans1,ans1); else { ll ans2=ans1,temp=1; for(int i=1;i<k;i++)temp=temp*(a-i+mod)%mod; temp=temp*b%mod; ans2=(ans2-temp+mod)%mod; printf("%I64d %I64d\n",ans2,ans1); } } return 0;}
阅读全文
1 0
- CodeForces 711 E.ZS and The Birthday Paradox(组合数学)
- Codeforces 711E ZS and The Birthday Paradox(数学)
- [Codeforces 711E] ZS and The Birthday Paradox (数学+Legendre公式)
- Codeforces 711E. ZS and The Birthday Paradox
- Codeforces 711E ZS and The Birthday Paradox
- 【28.57%】【codeforces 711E】ZS and The Birthday Paradox
- Codeforces 711 E. ZS and The Birthday Paradox(数学)——Codeforces Round #369 (Div. 2)
- codeforces Round#369 div2-E ZS and The Birthday Paradox(逆元,组合)★
- codeforces Round#369 div2-E ZS and The Birthday Paradox
- CodeForces 369 div2 E. ZS and The Birthday Paradox 数论
- cf/codeforces#369-E - ZS and The Birthday Paradox- 数学+gcd+逆元+勒让德定理
- codeforces ZS and The Birthday Paradox
- CodeForces-711E ZS and The Birthday Paradox(勒让德定理+抽屉原理)
- Codeforces 711E ZS and The Birthday Paradox 数论(Legendre's定理)
- Codeforces #369 (Div. 2) E. ZS and The Birthday Paradox (勒让德定理+逆元)
- 除法逆元(ZS and The Birthday Paradox,cf 711E)
- Codeforces Problem 711E ZS and The Birthday Paradox(抽屉原理+乘法逆元+费马小定理+组合数+快速幂+概率论)
- ZS and The Birthday Paradox
- 微信小程序周报(第七期)
- 网络流建模总结
- POJ 2250 Compromise(最长公共子序列 列出子序列)
- 新路程------hi3516a uboot测试网络是否正常
- springboot 集成freemarker
- CodeForces 711 E.ZS and The Birthday Paradox(组合数学)
- 网络爬虫的简介
- Linux下安装Tomcat服务器和部署Web应用
- 51C中_nop_(); 指令的说明和作用
- static 和 self的区别
- win10 + vs2013 +caffe 简易CPUonly安装步骤
- Common lisp编译成C可执行文件
- IDEA开发spring mvc 报404错误
- java se1.7 try-with-resources 使用