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 00simultaneously, 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:
- choose x=4x=4 and set a:=a−xa:=a−x, b:=b−2xb:=b−2x. Then a=6−4=2a=6−4=2, b=9−8=1b=9−8=1;
- choose x=1x=1 and set a:=a−2xa:=a−2x, b:=b−xb:=b−x. Then a=2−2=0a=2−2=0, b=1−1=0b=1−1=0.
这道题目 一开始做的时候思路就错了,我把这道题目想简单了,导致一直在纠结于找自己为什么 超时,直到解决了超时 问题wa之后才开始找新的思路。这道题目其实就是一道数学题目,需要我们自己在纸上进行推到就可
a=x1+x2+x3+…+xn+2y1+2y2+2y3+…+2yn;
b=2x1+2x2+2x3+…+2xn+y1+y2+y3+…+yn;
2a-b=3y1+3y2+3y3+…+3yn;
2a-b=3y
所以2a-b必须是3的倍数,且2*a>=b
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll t,n;
ll a,b;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>t;
while(t--)
{
cin>>a>>b;
if(a>b)
swap(a,b);
if((2*a-b)%3==0&&(2*a>=b))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
You are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor.
You must paint a fence which consists of 1010010100 planks in two colors in the following way (suppose planks are numbered from left to right from 00 ):
- if the index of the plank is divisible by rr (such planks have indices 00 , rr , 2r2r and so on) then you must paint it red;
- if the index of the plank is divisible by bb (such planks have indices 00 , bb , 2b2b and so on) then you must paint it blue;
- if the index is divisible both by rr and bb you can choose the color to paint the plank;
- otherwise, you don't need to paint the plank at all (and it is forbidden to spent paint on it).
Furthermore, the Government added one additional restriction to make your punishment worse. Let's list all painted planks of the fence in ascending order: if there are kk consecutive planks with the same color in this list, then the Government will state that you failed the labor and execute you immediately. If you don't paint the fence according to the four aforementioned conditions, you will also be executed.
The question is: will you be able to accomplish the labor (the time is not important) or the execution is unavoidable and you need to escape at all costs.
Input
The first line contains single integer TT (1≤T≤10001≤T≤1000 ) — the number of test cases.
The next TT lines contain descriptions of test cases — one per line. Each test case contains three integers rr , bb , kk (1≤r,b≤1091≤r,b≤109 , 2≤k≤1092≤k≤109 ) — the corresponding coefficients.
Output
Print TT words — one per line. For each test case print REBEL (case insensitive) if the execution is unavoidable or OBEY (case insensitive) otherwise.
Example
Input
4 1 1 2 2 10 4 5 2 3 3 2 2
Output
OBEY REBEL OBEY OBEY
这个题目在上午做的时候就确实是没有什么思路,想了很久都没有什么结果,下午补题的时侯是搜了题解才弄明白这道题目,但其实现在看来想要实现这个题目并不难,只需要很小的代码量。
显然通过题意我们可以知道在r 和b 的最小公倍数左右两种颜色是一样的,所以只需要考虑每个公倍数为一段之间的最长连续色块。假设r>b ,我们计算最长色块,那么边上的色块长度是r/b 。
先将r 和b 除于最小公因数g,考虑计算中间的,因为无限延伸,总会有一种情况使得一个蓝色块搞好在红色块的后第g个位置,那么此时是中间最长的,长度为(r−2)/b+1,根据这些直接判断即可
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define ll long long
using namespace std;
ll t,a,b,k;
ll gcd(ll x,ll y){
if(!y)
return x;
return
gcd(y,x%y);
}
int main()
{
cin>>t;
while(t--){
cin>>a>>b>>k;
if(k==1){
cout<<"REBEL"<<endl;
continue;
}
if(a<b)
swap(a,b);
ll g=gcd(a,b);
a/=g;b/=g;
if(a==1&&b==1)
cout<<"OBEY"<<endl;
else if(b==1){
if(a-b>=k)
cout<<"REBEL"<<endl;
else
cout<<"OBEY"<<endl;
}
else{
ll c=(a-2)/b+1,z=a/b;
if(c>=k||z>=k)
cout<<"REBEL"<<endl;
else
cout<<"OBEY"<<endl;
}
}
}
这一次还是就只出了两个题目,怀揣一个美好的心愿,明天出三个!!!