C. Infinite Fence
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 10100 planks in two colors in the following way (suppose planks are numbered from left to right from 0):
if the index of the plank is divisible by r (such planks have indices 0, r, 2r and so on) then you must paint it red;
if the index of the plank is divisible by b (such planks have indices 0, b, 2b and so on) then you must paint it blue;
if the index is divisible both by r and b 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 k 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 T (1≤T≤1000) — the number of test cases.
The next T lines contain descriptions of test cases — one per line. Each test case contains three integers r, b, k (1≤r,b≤109, 2≤k≤109) — the corresponding coefficients.
Output
Print T words — one per line. For each test case print REBEL (case insensitive) if the execution is unavoidable or OBEY (case insensitive) otherwise.
一道数学题,假设 r>b ,那么我们要计算[r,2*r]这个区间的b的倍数的个数,如果个数大于等于k,那么失败,反之胜利;
这里就有一个规律了,如果 r 和 b 互质,那么[r,2*r]这个区间的 b 的倍数个数就为 s=(r-2)/b+1
这个式子怎么来的呢?首先我们推出每个r到2*r这个区间的长度为 r-1,那么最少会有 (r-1)/b个b的倍数,如果有余数,那么一定还存在一个b的倍数,也就是 (r-2)/b+1 个,至于怎么证明。。。。
代码:
#include<bits/stdc++.h>
#define LL long long
#define pa pair<int,int>
#define lson k<<1
#define rson k<<1|1
#define inf 0x3f3f3f3f
//ios::sync_with_stdio(false);
using namespace std;
const int N=200100;
const int M=400100;
const LL mod=998244353;
int main(){
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--){
int r,b,k;
cin>>r>>b>>k;
int t=__gcd(r,b);
r/=t,b/=t;
if(r<b) swap(r,b);
if((r-2)/b+1>=k) cout<<"REBEL"<<endl;
else cout<<"OBEY"<<endl;
}
return 0;
}