A14831 | Make AP
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarp has $3$ positive integers $a$ , $b$ and $c$ . He can perform the following operation exactly once.
- Choose a positive integer $m$ and multiply exactly one of the integers $a$ , $b$ or $c$ by $m$ .
Can Polycarp make it so that after performing the operation, the sequence of three numbers $a$ , $b$ , $c$ (in this order) forms an [arithmetic progression](https://en.wikipedia.org/wiki/Arithmetic_progression)? Note that you cannot change the order of $a$ , $b$ and $c$ .
Formally, a sequence $x_1, x_2, \dots, x_n$ is called an arithmetic progression (AP) if there exists a number $d$ (called "common difference") such that $x_{i+1}=x_i+d$ for all $i$ from $1$ to $n-1$ . In this problem, $n=3$ .
For example, the following sequences are AP: $[5, 10, 15]$ , $[3, 2, 1]$ , $[1, 1, 1]$ , and $[13, 10, 7]$ . The following sequences are not AP: $[1, 2, 4]$ , $[0, 1, 0]$ and $[1, 3, 2]$ .
You need to answer $t$ independent test cases.
- Choose a positive integer $m$ and multiply exactly one of the integers $a$ , $b$ or $c$ by $m$ .
Can Polycarp make it so that after performing the operation, the sequence of three numbers $a$ , $b$ , $c$ (in this order) forms an [arithmetic progression](https://en.wikipedia.org/wiki/Arithmetic_progression)? Note that you cannot change the order of $a$ , $b$ and $c$ .
Formally, a sequence $x_1, x_2, \dots, x_n$ is called an arithmetic progression (AP) if there exists a number $d$ (called "common difference") such that $x_{i+1}=x_i+d$ for all $i$ from $1$ to $n-1$ . In this problem, $n=3$ .
For example, the following sequences are AP: $[5, 10, 15]$ , $[3, 2, 1]$ , $[1, 1, 1]$ , and $[13, 10, 7]$ . The following sequences are not AP: $[1, 2, 4]$ , $[0, 1, 0]$ and $[1, 3, 2]$ .
You need to answer $t$ independent test cases.
输入格式
The first line contains the number $t$ ( $1 \le t \le 10^4$ ) — the number of test cases.
Each of the following $t$ lines contains $3$ integers $a$ , $b$ , $c$ ( $1 \le a, b, c \le 10^8$ ).
Each of the following $t$ lines contains $3$ integers $a$ , $b$ , $c$ ( $1 \le a, b, c \le 10^8$ ).
输出格式
For each test case print "YES" (without quotes) if Polycarp can choose a positive integer $m$ and multiply exactly one of the integers $a$ , $b$ or $c$ by $m$ to make $[a, b, c]$ be an arithmetic progression. Print "NO" (without quotes) otherwise.
You can print YES and NO in any (upper or lower) case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive answer).
You can print YES and NO in any (upper or lower) case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive answer).
输入输出样例
输入 #1
11 10 5 30 30 5 10 1 2 3 1 6 3 2 6 3 1 1 1 1 1 2 1 1 3 1 100000000 1 2 1 1 1 2 2
输出 #1
YES YES YES YES NO YES NO YES YES NO YES
In the first and second test cases, you can choose the number $m=4$ and multiply the second number ( $b=5$ ) by $4$ .
In the first test case the resulting sequence will be $[10, 20, 30]$ . This is an AP with a difference $d=10$ .
In the second test case the resulting sequence will be $[30, 20, 10]$ . This is an AP with a difference $d=-10$ .
In the third test case, you can choose $m=1$ and multiply any number by $1$ . The resulting sequence will be $[1, 2, 3]$ . This is an AP with a difference $d=1$ .
In the fourth test case, you can choose $m=9$ and multiply the first number ( $a=1$ ) by $9$ . The resulting sequence will be $[9, 6, 3]$ . This is an AP with a difference $d=-3$ .
In the fifth test case, it is impossible to make an AP.
In the first test case the resulting sequence will be $[10, 20, 30]$ . This is an AP with a difference $d=10$ .
In the second test case the resulting sequence will be $[30, 20, 10]$ . This is an AP with a difference $d=-10$ .
In the third test case, you can choose $m=1$ and multiply any number by $1$ . The resulting sequence will be $[1, 2, 3]$ . This is an AP with a difference $d=1$ .
In the fourth test case, you can choose $m=9$ and multiply the first number ( $a=1$ ) by $9$ . The resulting sequence will be $[9, 6, 3]$ . This is an AP with a difference $d=-3$ .
In the fifth test case, it is impossible to make an AP.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted