博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2773 Happy 2006
阅读量:5328 次
发布时间:2019-06-14

本文共 1947 字,大约阅读时间需要 6 分钟。

Happy 2006

Time Limit: 3000ms
Memory Limit: 65536KB
This problem will be judged on 
PKU. Original ID: 
64-bit integer IO format: %lld      Java class name: Main
 
Two positive integers are said to be relatively prime to each other if the Great Common Divisor (GCD) is 1. For instance, 1, 3, 5, 7, 9...are all relatively prime to 2006.
Now your job is easy: for the given integer m, find the K-th element which is relatively prime to m when these elements are sorted in ascending order.
 

Input

The input contains multiple test cases. For each test case, it contains two integers m (1 <= m <= 1000000), K (1 <= K <= 100000000).
 

Output

Output the K-th element in a single line.
 

Sample Input

2006 12006 22006 3

Sample Output

135

Source

 
解题:容斥原理
1 #include 
2 #include
3 #include
4 using namespace std; 5 typedef long long LL; 6 const LL INF = 0x3f3f3f3f3f3f3f3f; 7 const int maxn = 50; 8 int p[maxn],tot; 9 void init(int x){10 tot = 0;11 for(int i = 2; i*i <= x; ++i){12 if(x%i == 0){13 p[tot++] = i;14 while(x%i == 0) x /= i;15 }16 }17 if(x > 1) p[tot++] = x;18 }19 LL solve(LL x){20 LL ret = 0;21 for(int i = 1; i < (1<
>j)&1){25 ++cnt;26 tmp *= p[j];27 }28 }29 if(cnt&1) ret -= x/tmp;30 else ret += x/tmp;31 }32 return x + ret;33 }34 int main(){35 int n,k;36 while(~scanf("%d%d",&n,&k)){37 LL ret = 0,low = 1,high = INF;38 init(n);39 while(low <= high){40 LL mid = (low + high)>>1;41 if(solve(mid) >= k){42 ret = mid;43 high = mid - 1;44 }else low = mid + 1;45 }46 printf("%I64d\n",ret);47 }48 return 0;49 }
View Code

 

转载于:https://www.cnblogs.com/crackpotisback/p/4850806.html

你可能感兴趣的文章
安装Endnote X6,但Word插件显示的总是Endnote Web"解决办法
查看>>
python全栈 计算机硬件管理 —— 硬件
查看>>
大数据学习
查看>>
简单工厂模式
查看>>
Delphi7编译的程序自动中Win32.Induc.a病毒的解决办法
查看>>
Objective-C 【关于导入类(@class 和 #import的区别)】
查看>>
倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-点击运行按钮进入到运行状态报错Error starting TwinCAT System怎么办 AdsWarning1823怎么办...
查看>>
【转】javascript 中的很多有用的东西
查看>>
Centos7.2正常启动关闭CDH5.16.1
查看>>
Android 监听返回键、HOME键
查看>>
Android ContentProvider的实现
查看>>
sqlserver 各种判断是否存在(表名、函数、存储过程等)
查看>>
给C#学习者的建议 - CLR Via C# 读后感
查看>>
Recover Binary Search Tree
查看>>
Java 实践:生产者与消费者
查看>>
[转]IOCP--Socket IO模型终结篇
查看>>
js 获取视频的第一帧
查看>>
各种正则验证
查看>>
观察者模式(Observer)
查看>>
python中numpy.r_和numpy.c_
查看>>