Codeforces Round #767 (Div. 2)
比赛链接
Codeforces Round #767 (Div. 2)
B. GCD Arrays
Consider the array composed of all the integers in the range . For example, if and , then .
Given , and , is it possible for to be greater than after doing the following operation at most times?
Choose numbers from .
Permanently remove one occurrence of each of them from the array.
Insert their product back into .
denotes the greatest common divisor (GCD) of the integers in .
Input
The first line of the input contains a single integer — the number of test cases. The description of test cases follows.
The input for each test case consists of a single line containing non-negative integers , and .
Output
For each test case, print "YES"
if it is possible to have the GCD of the corresponding array greater than 1 by performing at most k operations, and "NO"
otherwise (case insensitive).
Example
input
output
Note
For the first test case, , so the answer is "NO"
, since the only element in the array is .
For the second test case the array is and we have operation. After the first operation the array can change to: or all of which having their greatest common divisor equal to 1 so the answer is "NO"
.
For the third test case, , so the answer is "YES"
, since the only element in the array is .
For the fourth test case, , so the answer is "YES"
, since the only element in the array is .
解题思路
思维题
由于数是连续的,一些数的倍数关系,所有数的分解质因数出现的最大次数的质数是 ,所以只需要找出奇数出现的次数,每一次操作用偶数合并,即奇数个数减一。最终转换为奇数个数是否小于等于 ,另外需要特判 的情况。这里求奇数个数有个公式,可转换为求偶数个数:
- 时间复杂度:
代码
__EOF__

本文链接:https://www.cnblogs.com/zyyun/p/15835708.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!