B. Obtain Two Zeroes -Codeforces Round 77 (Div. 2)

http://codeforces.com/contest/1260/problem/B

B. Obtain Two Zeroes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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:=axa:=a−x, b:=b2xb:=b−2x or a:=a2xa:=a−2x, b:=bxb:=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 (1t1001≤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 (0a,b1090≤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:=axa:=a−x, b:=b2xb:=b−2x. Then a=64=2a=6−4=2, b=98=1b=9−8=1;
  2. choose x=1x=1 and set a:=a2xa:=a−2x, b:=bxb:=b−x. Then a=22=0a=2−2=0, b=11=0b=1−1=0.

题意:

  每次给定两个数

  可以对两个数进行若干次操作

  每次操作在一个数上减掉x,在另一个数上减掉2x

  输出是否能同时变成0

解法:

  不放设两个数a、b,且 a < b

  则 b > 2a 时无解(不存在 x 使得b - 2x = a - x = 0)

  每次操作先让a减少2,b减少1;再让a减少1,b减少2,

  这样一组操作后,两个数同时减少3,

  两个数在同时减少 3n 后,能变成1 : 2的整数就可解

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
//#define sort(a,n,int) sort(a,a+n,less<int>())

#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db;

const double PI=acos(-1.0);
const double eps=1e-6;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;

int main()
{
    int  a , b , t;
    cin >>t;
    while(t--)
    {
        cin >>a >>b;
        if(a>b)
        {
            int change = a;
            a = b;
            b = change;
        }
        if((2*a-b)<0)
        {
            cout <<"NO" <<endl;
            continue;
        }
        if((2*a-b)%3)
        {
            cout <<"NO" <<endl;
            continue;
        }
        else
        {
            cout <<"YES" <<endl;
            continue;
        }
    }
    return 0;
}

/*
3

1 1 !
1 2
2 2 !
*/

作者:YukiRinLL

出处:YukiRinLL的博客--https://www.cnblogs.com/SutsuharaYuki/

您的支持是对博主最大的鼓励,感谢您的认真阅读。

本文版权归作者所有,欢迎转载,但请保留该声明。

原文地址:https://www.cnblogs.com/SutsuharaYuki/p/11947435.html