B. Obtain Two Zeroes
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given two integers a and b. You may perform any number of operations on them (possibly zero).
During each operation you should choose any positive integer x and set a:=a−x, b:=b−2x or a:=a−2x, b:=b−x. Note that you may choose different values of x in different operations.
Is it possible to make a and b equal to 0 simultaneously?
Your program should answer t independent test cases.
Input
The first line contains one integer t (1≤t≤100) — the number of test cases.
Then the test cases follow, each test case is represented by one line containing two integers a and b for this test case (0≤a,b≤109).
Output
For each test case print the answer to it — YES if it is possible to make a and b equal to 0 simultaneously, and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
inputCopy
3
6 9
1 1
1 2
outputCopy
YES
NO
YES
Note
In the first test case of the example two operations can be used to make both a and b equal to zero:
choose x=4 and set a:=a−x, b:=b−2x. Then a=6−4=2, b=9−8=1;
choose x=1 and set a:=a−2x, b:=b−x. Then a=2−2=0, b=1−1=0.
给你两个数a b,通过多次操作(操作次数可能为0),能否使a b同时变为0
对a有两种操作,-x和-2x,将所有-x操作相加,相当于对a执行一个大操作 -X,
即设X=x1+x2+…+xn,同理可设另一个大操作为-Y,
对应地,对b也有两种操作,而且 X Y 刚好与a相反, 可得两个方程
a=X+2Y 解得 X=(a-2b) / (-3)
b=2X+Y Y=(2a-b) / 3
由于每次操作中x为正整数,但操作数可能为0,所以X Y 为 >=0的整数
代入a b检验,若计算得到的X Y满足上述条件,则符合题意
#include
using namespace std;
int main()
{
int t;
long long a,b;
cin>>t;
while(t--){
cin>>a>>b;
long long X=-2*a+4*b; //X/6 Y/6 分别为两种操作中 x的总和
long long Y=4*a-2*b; //必为正整数 但操作数为0时 X Y可为0
if( X%6==0 && Y%6==0 &&X>=0 &&Y>=0) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}