https://codeforces.com/problemset/problem/1260/C
现有10^100块木板需要涂漆.
第x块如果是x是a的倍数,则涂R颜色.
是b的倍数,则涂B颜色。
如果既是a又是b的倍数,那么两种颜色都可以涂;
如果连续有k块板的颜色是一样的,则输出REBEL,否则输出OBEY。
思路:
首先不妨假设r<b。比较明显的是r的倍数肯定比b多。
b的颜色都是b*1,b*2,b*3,....b*n
可能会觉得每个间隔之间的a的倍数是一样多的。开始我也这么搞的..是存在反例的。
5 12 3 这组,5 10 12 15 20 24 25 30 35 36 40 45 48 50 55 60。
在B=24~B=36中间有三个。这就是关键的地方了。判这里就好。
贪心要让其中一个间隔放下最多的a
那么就是让一个a的倍数,离一个b的上一个的倍数最近。设相差距离为c
那么就可以得出x*a+y*b=c;
这个方程怎么样有解呢?裴蜀定理可得c为gcd(a,b)的倍数可解。
那么贪心让倍数最小。
于是c=gcd(a,b)
那么(b,b+b)中间一共b-1个,加上gcd(a,b)一个,(b-1-gcd(a,b))/a后面每隔a个一个
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
int main(void)
{
cin.tie(0);std::ios::sync_with_stdio(false);
LL t;cin>>t;
while(t--){
LL r,b,k;cin>>r>>b>>k;
if(r>b) swap(r,b);
if(r==b){
cout<<"OBEY"<<"\n";
}
else{
LL cnt=1+(b-1-__gcd(r,b))/r;
if(cnt<k){
cout<<"OBEY"<<"\n";
}
else cout<<"REBEL"<<"\n";
}
}
return 0;
}