Polycarp has 333 positive integers aaa, bbb and ccc. He can perform the following operation exactly once.
- Choose a positive integer mmm and multiply exactly one of the integers aaa, bbb or ccc by mmm.
Can Polycarp make it so that after performing the operation, the sequence of three numbers aaa, bbb, ccc (in this order) forms an arithmetic progression? Note that you cannot change the order of aaa, bbb and ccc.
Formally, a sequence x1,x2,…,xnx_1, x_2, \dots, x_nx1,x2,…,xn is called an arithmetic progression (AP) if there exists a number ddd (called "common difference") such that xi+1=xi+dx_{i+1}=x_i+dxi+1=xi+d for all iii from 111 to n−1n-1n−1. In this problem, n=3n=3n=3.
For example, the following sequences are AP: [5,10,15][5, 10, 15][5,10,15], [3,2,1][3, 2, 1][3,2,1], [1,1,1][1, 1, 1][1,1,1], and [13,10,7][13, 10, 7][13,10,7]. The following sequences are not AP: [1,2,4][1, 2, 4][1,2,4], [0,1,0][0, 1, 0][0,1,0] and [1,3,2][1, 3, 2][1,3,2].
You need to answer ttt independent test cases.
Input
The first line contains the number ttt (1≤t≤1041 \le t \le 10^41≤t≤104) — the number of test cases.
Each of the following ttt lines contains 333 integers aaa, bbb, ccc (1≤a,b,c≤1081 \le a, b, c \le 10^81≤a,b,c≤108).
Output
For each test case print "YES" (without quotes) if Polycarp can choose a positive integer mmm and multiply exactly one of the integers aaa, bbb or ccc by mmm to make [a,b,c][a, b, c][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).
Sample 1
Inputcopy | Outputcopy |
---|---|
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 | YES YES YES YES NO YES NO YES YES NO YES |
这个题要我们将输入的三个数中其中一个数乘K,之后使这三个数成为一个等差数列。
等差数列的性质:a+c=2b。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
int t;cin>>t;
while(t--)
{
int a,b,c;
cin>>a>>b>>c;
if(a+c==2*b)
cout<<"YES"<<endl;
else
{
if(2*b<a+c)
{
if((a+c)%(2*b)==0) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
else
{
if((2*b-c)%a==0||(2*b-a)%c==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
}
}