poj 2773
来源:互联网 发布:会员视频源码 编辑:程序博客网 时间:2024/06/07 00:45
(二分+容斥原理)
题意:求第
思路:二分
代码:
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#define LL long longusing namespace std;const double eps = 1e-8;bool vis[100100];LL fac[100100];/*LL solve(LL x, LL cnt){ LL ret = 0; for(LL i=1; i<(1<<cnt); i++){ LL bits = 0, mul = 1; for(LL j=0; j<cnt; j++)if(i&(1<<j)){ bits ++; mul *= fac[j]; } if(bits&1) ret += x/mul; else ret -= x/mul; } return x - ret;}*/LL solve(LL m, LL x, LL cnt){ LL ret = 0; for(int i=x; i<cnt; i++){ ret += m/fac[i] - solve(m/fac[i], i+1, cnt); } return ret;}int main(){ //freopen("test.txt","r",stdin); LL m, k; while(scanf("%lld%lld",&m,&k) == 2){ LL cnt = 0, tm = m; for(LL i=2; i*i<=tm; i++) if(tm%i == 0){ fac[cnt++] = i; while(tm%i == 0) tm /= i; } if(tm > 1) fac[cnt++] = tm; LL l = 1, r = 1000000000000; while(l < r){ LL mid = (r-l)/2 + l; //if(solve(mid, cnt) >= k) r = mid; if(mid - solve(mid, 0, cnt) >= k) r = mid; else l = mid + 1; } printf("%lld\n",l); } return 0;}
阅读全文
0 0
- POJ 2773
- poj 2773
- POJ-------2773
- POJ 2773
- poj 2773
- POJ 2773 Happy 2006
- poj 2773 Happy 2006
- poj 2773 Happy 2006
- POJ 2773 欧几里德
- poj 2773 Happy 2006
- poj 2773 Happy 2006
- POJ 2773 Happy 2006
- poj 2773 Happy 2006
- POJ 2773 Happy 2006
- poj 2773 Happy 2006
- poj 2773 Happy 2006
- POJ 2773 Happy 2006
- poj 2773 Happy 2006
- STL 关联容器 之set(无重复有序集合)
- JAVA学习-序号2 HashSet初入门,hashCode和equals方法
- eclipse中如何向开源中国(码云)上传代码
- HDU
- 开启新的篇章
- poj 2773
- linux上搭建zookeeper集群
- SSM框架的基本搭建(Spring+Struts+Mybatis)
- "扇贝杯"南邮第二届软件和信息技术专业人才大赛题解
- 算法的一些小栗子4(归并排序)
- java常量池测试总结
- 线程的知识点总结1。Join线程的使用
- 二叉树的遍历非递归
- POJ