Description:
\quad You are a rebel leader and you are planning to start a a a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor.
\quad You must paint a fence which consists of 1 0 100 10^{100} 10100planks in two colors in the following way (suppose planks are numbered from left to right from 0):
\quad
if the index of the plank is divisible by r (such planks have indices
0
,
r
,
2
r
0, r, 2r
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
,
2
b
0, b, 2b
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;
\quad
otherwise, you don’t need to paint the plank at all (and it is forbidden to spent paint on it).
\quad
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.
\quad 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
\quad The first line contains single integer T ( 1 ≤ T ≤ 2 ∗ 1000 ) T\left(1≤T≤2*1000 \right) T(1≤T≤2∗1000) — the number of test cases.
\quad The next T T T lines contain descriptions of test cases — one per line. Each test case contains three integers r , b , k ( 1 ≤ r , b ≤ 1 0 9 , 2 ≤ k ≤ 1 0 9 ) r,b,k\left(1≤r,b≤10^{9} ,2≤k≤10^{9} \right) r,b,k(1≤r,b≤109,2≤k≤109)— the corresponding coefficients.
Output
\quad Print T T T words — one per line. For each test case print R E B E L REBEL REBEL (case insensitive) if the execution is unavoidable or O B E Y OBEY OBEY (case insensitive) otherwise.
Example
input
4
1 1 2
2 10 4
5 2 3
3 2 2
output
OBEY
REBEL
OBEY
OBEY
\quad
现有
1
0
100
10^{100}
10100块木板需要涂漆,第x块如果是x是a的倍数,则涂一种颜色,是b的倍数,则涂另一种颜色。如果既是a又是b的倍数,那么两种颜色都可以涂;如果连续有k块板的颜色是一样的,则输出REBEL,否则输出OBEY。问是否能避免被处死。我们肯定优先使不被处死.。
\quad
我们先假设
r
r
r是小的,
b
b
b是大的。那么最长连续区间肯定是
r
r
r的倍数染的色。
b
b
b的染色情况为
b
,
2
b
,
3
b
.
.
.
.
k
b
。
r
b,2b,3b....kb。r
b,2b,3b....kb。r可以出现的位置肯定在两个
b
b
b的倍数之间,那么
r
r
r可以出现的区间长度肯定是
b
−
1
。
b-1。
b−1。我们考虑最坏的情况那
r
r
r在一个区间出现大的位置肯定要尽可能的早设这个位置为
t
t
t。那么满足式子
k
1
b
+
t
=
k
2
r
k_{1}b+t=k_{2}r
k1b+t=k2r。
\quad
由
e
x
g
c
d
exgcd
exgcd 可得
a
x
+
b
y
=
c
ax+by=c
ax+by=c 当且仅当
g
c
d
(
a
,
b
)
∣
c
gcd(a,b)|c
gcd(a,b)∣c 有解。
c
c
c 最小为
g
c
d
(
a
,
b
)
gcd(a,b)
gcd(a,b)。即
t
t
t最小为
g
c
d
(
r
,
b
)
gcd(r,b)
gcd(r,b) 。则最多连续的木板数为
(
b
−
1
)
−
g
c
d
(
r
,
b
)
r
+
1
\frac{(b-1)-gcd(r,b)}{r}+1
r(b−1)−gcd(r,b)+1。把这个数和
k
k
k比较就能得到答案。
AC代码:
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n,m) printf("%d %d", n, m)
#define pld(n) printf("%lld\n", n)
#define pldd(n,m) printf("%lld %lld\n", n, m)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sc(n) scanf("%c",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define mem(a,n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mod(x) ((x)%MOD)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const int maxn = 3e5 + 5;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
int ret = 0, sgn = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-')
sgn = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
ret = ret*10 + ch - '0';
ch = getchar();
}
return ret*sgn;
}
inline void Out(int a) //Êä³öÍâ¹Ò
{
if(a>9)
Out(a/10);
putchar(a%10+'0');
}
int qpow(int m, int k, int mod)
{
int res = 1, t = m;
while (k)
{
if (k&1)
res = res * t % mod;
t = t * t % mod;
k >>= 1;
}
return res;
}
ll gcd(ll a,ll b)
{
return b==0?a : gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a*b/gcd(a,b);
}
int n,m;
int i,j;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll r,b,k;
scanf("%lld%lld%lld",&r,&b,&k);
if(r>b)
swap(r,b);
ll ans=((b-1)-gcd(r,b))/r+1;
if(k<=ans)
printf("REBEL\n");
else
printf("OBEY\n");
}
return 0;
}