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 !
*/

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YukiRinLL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值