CF1624B.Make AP
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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? Note that you cannot change the order of a, b and c.
Formally, a sequence x1,x2,…,xn is called an arithmetic progression (AP) if there exists a number d (called "common difference") such that xi+1=xi+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.
Polycarp 有三个正整数 a、b 和 c。他恰好可以执行以下操作一次:
- 选择一个正整数 m,并将 a、b、c 中的恰好一个数乘以 m。
Polycarp 能否通过执行该操作,使得操作后的三个数 a、b、c(按此顺序)构成一个等差数列?注意:你不能改变 a、b、c 的顺序。
形式化地,序列 x1,x2,…,xn 被称为等差数列(AP),当且仅当存在一个数 d(称为“公差”),使得对所有从 1 到 n−1 的 i,均有 xi+1=xi+d。在本题中,n=3。
例如,以下序列是等差数列:[5,10,15]、[3,2,1]、[1,1,1] 和 [13,10,7];以下序列不是等差数列:[1,2,4]、[0,1,0] 和 [1,3,2]。
你需要回答 t 个相互独立的测试用例。
输入格式
The first line contains the number t (1≤t≤104) — the number of test cases.
Each of the following t lines contains 3 integers a, b, c (1≤a,b,c≤108).
第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
接下来的 t 行,每行包含三个整数 a、b、c(1≤a,b,c≤108)。
输出格式
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).
对于每个测试用例,如果 Polycarp 能够选择一个正整数 m,并将 a、b 或 c 中的恰好一个整数乘以 m,使得 [a,b,c] 成为一个等差数列,则输出 "YES"(不带引号);否则输出 "NO"(不带引号)。
你可以以任意大小写形式输出 YES 和 NO(例如,字符串 yEs、yes、Yes 和 YES 均会被识别为肯定回答)。
输入输出样例
输入#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.
在第一和第二个测试用例中,你可以选择数字 m=4,并将第二个数(b=5)乘以 4。
在第一个测试用例中,得到的序列为 [10,20,30]。这是一个公差为 d=10 的等差数列(AP)。
在第二个测试用例中,得到的序列为 [30,20,10]。这是一个公差为 d=−10 的等差数列(AP)。
在第三个测试用例中,你可以选择 m=1,并将任意一个数乘以 1。得到的序列为 [1,2,3]。这是一个公差为 d=1 的等差数列(AP)。
在第四个测试用例中,你可以选择 m=9,并将第一个数(a=1)乘以 9。得到的序列为 [9,6,3]。这是一个公差为 d=−3 的等差数列(AP)。
在第五个测试用例中,无法构造出等差数列(AP)。
输入解题思路,AI测评打分。不知道怎么写?