Obtain Two Zeroes//CodeForces - 1260B//思维

Obtain Two Zeroes//CodeForces - 1260B//思维


题目

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
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 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,每次通过a-x,b-2x或a-2x,b-x使得a,b为0
链接:http://codeforces.com/problemset/problem/1260/B

思路

a与b的和可被3整除即可

代码

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if((a+b)%3!=0||a>b*2||b>a*2)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
    return 0;
}

注意

a可能比b的2倍还多

发布了24 篇原创文章 · 获赞 9 · 访问量 536

猜你喜欢

转载自blog.csdn.net/salty_fishman/article/details/103964295