CodeForces - 1260B

L - 二分???

CodeForces - 1260B

You are given two integers aa and bb. You may perform any number of operations on them (possibly zero).

During each operation you should choose any positive integer xx and set a:=a−xa:=a−x, b:=b−2xb:=b−2x or a:=a−2xa:=a−2x, b:=b−xb:=b−x. Note that you may choose different values of xx in different operations.

Is it possible to make aa and bb equal to 00 simultaneously?

Your program should answer tt independent test cases.

Input

The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.

Then the test cases follow, each test case is represented by one line containing two integers aa and bb for this test case (0≤a,b≤1090≤a,b≤109).

Output

For each test case print the answer to it — YES if it is possible to make aa and bb equal to 00 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

Input

3
6 9
1 1
1 2

Output

YES
NO
YES

Note

In the first test case of the example two operations can be used to make both aa and bb equal to zero:

1.choose x=4x=4 and set a:=a−xa:=a−x, b:=b−2xb:=b−2x. Then a=64=2a=64=2, b=98=1b=98=1;

2.choose x=1x=1 and set a:=a−2xa:=a−2x, b:=b−xb:=b−x. Then a=22=0a=22=0, b=11=0b=11=0.

题目描述:

给定2个整数a,b。可以对a,b进行下面2个操作任意次:

1.a=a-x&&b=b-2x

2.a=a-2y&&b=b-y

(x,y为正整数)

问能否是a,b同时变成0。

由于是任意次操作,假设操作1进行A次,操作2进行B次。假设能同时为0,就有式子:a-Ax-2By=0,b-2Ax-By=0;

加起来就得到(a+b)/3=Ax+By。只要满足此式即可。

先考虑没有0的情况:

可以发现规律,只要大的数满足小于小的数的2倍,就能凑出正整数Ax和By。

再考虑有0的情况,假设a=0,代入a-Ax-2By=0,b-2Ax-By=0;就可以得到b=-3By;b一定是3的倍数,所以一定满足(a+b)/3=Ax+By。b=0也同理。

代码:

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int a,b;
        cin>>a;
        cin>>b;
        if(a>b)
        {
            if((a+b)%3==0&&a<=2*b)
            cout<<"YES\n";
            else
            cout<<"NO\n";
        }
        else
        {
            if((a+b)%3==0&&b<=2*a)
            cout<<"YES\n";
            else
            cout<<"NO\n";
        }
        
    }
    return 0;
}

 

猜你喜欢

转载自www.cnblogs.com/studyshare777/p/12186117.html