A14799 | GCD Arrays
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Consider the array $a$ composed of all the integers in the range $[l, r]$ . For example, if $l = 3$ and $r = 7$ , then $a = [3, 4, 5, 6, 7]$ .
Given $l$ , $r$ , and $k$ , is it possible for $\gcd(a)$ to be greater than $1$ after doing the following operation at most $k$ times?
- Choose $2$ numbers from $a$ .
- Permanently remove one occurrence of each of them from the array.
- Insert their product back into $a$ .
$\gcd(b)$ denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of the integers in $b$ .
Given $l$ , $r$ , and $k$ , is it possible for $\gcd(a)$ to be greater than $1$ after doing the following operation at most $k$ times?
- Choose $2$ numbers from $a$ .
- Permanently remove one occurrence of each of them from the array.
- Insert their product back into $a$ .
$\gcd(b)$ denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of the integers in $b$ .
输入格式
The first line of the input contains a single integer $t$ ( $1 \le t \le 10^5$ ) — the number of test cases. The description of test cases follows.
The input for each test case consists of a single line containing $3$ non-negative integers $l$ , $r$ , and $k$ ( $1 \leq l \leq r \leq 10^9, \enspace 0 \leq k \leq r - l$ ).
The input for each test case consists of a single line containing $3$ non-negative integers $l$ , $r$ , and $k$ ( $1 \leq l \leq r \leq 10^9, \enspace 0 \leq k \leq r - l$ ).
输出格式
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).
输入输出样例
输入 #1
9 1 1 0 3 5 1 13 13 0 4 4 0 3 7 4 4 10 3 2 4 0 1 7 3 1 5 3
输出 #1
NO NO YES YES YES YES NO NO YES
For the first test case, $a = [1]$ , so the answer is "NO", since the only element in the array is $1$ .
For the second test case the array is $a = [3, 4, 5]$ and we have $1$ operation. After the first operation the array can change to: $[3, 20]$ , $[4, 15]$ or $[5, 12]$ all of which having their greatest common divisor equal to $1$ so the answer is "NO".
For the third test case, $a = [13]$ , so the answer is "YES", since the only element in the array is $13$ .
For the fourth test case, $a = [4]$ , so the answer is "YES", since the only element in the array is $4$ .
For the second test case the array is $a = [3, 4, 5]$ and we have $1$ operation. After the first operation the array can change to: $[3, 20]$ , $[4, 15]$ or $[5, 12]$ all of which having their greatest common divisor equal to $1$ so the answer is "NO".
For the third test case, $a = [13]$ , so the answer is "YES", since the only element in the array is $13$ .
For the fourth test case, $a = [4]$ , so the answer is "YES", since the only element in the array is $4$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted