Educational Codeforces Round 77 (Rated for Div. 2) C题

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值