Codeforces 1260C Infinite Fence(扩展欧几里得)

探讨一个编程问题,作为叛逆者领袖,你需要在政府的惩罚任务中,通过编程策略来避免连续相同颜色的木板超过限定数量,从而逃过死刑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description:

\quadYou are a rebel leader and you are planning to start aaa revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor.

\quadYou must paint a fence which consists of 1010010^{100}10100planks in two colors in the following way (suppose planks are numbered from left to right from 0):

\quadif the index of the plank is divisible by r (such planks have indices 0,r,2r0, r, 2r0,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,2b0, b, 2b0,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;
\quadotherwise, you don’t need to paint the plank at all (and it is forbidden to spent paint on it).
\quadFurthermore, 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.

\quadThe 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

\quadThe first line contains single integer T(1≤T≤2∗1000)T\left(1≤T≤2*1000 \right)T(1T21000) — the number of test cases.

\quadThe next TTT 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)r,b,k\left(1≤r,b≤10^{9} ,2≤k≤10^{9} \right)r,b,k(1r,b109,2k109)— the corresponding coefficients.

Output

\quadPrint TTT words — one per line. For each test case print REBELREBELREBEL (case insensitive) if the execution is unavoidable or OBEYOBEYOBEY (case insensitive) otherwise.

Example

input

4
1 1 2
2 10 4
5 2 3
3 2 2

output

OBEY
REBEL
OBEY
OBEY

\quad现有1010010^{100}10100块木板需要涂漆,第x块如果是x是a的倍数,则涂一种颜色,是b的倍数,则涂另一种颜色。如果既是a又是b的倍数,那么两种颜色都可以涂;如果连续有k块板的颜色是一样的,则输出REBEL,否则输出OBEY。问是否能避免被处死。我们肯定优先使不被处死.。
\quad我们先假设rrr是小的,bbb是大的。那么最长连续区间肯定是rrr的倍数染的色。bbb的染色情况为b,2b,3b....kb。rb,2b,3b....kb。rb2b3b....kbr可以出现的位置肯定在两个bbb的倍数之间,那么rrr可以出现的区间长度肯定是b−1。b-1。b1我们考虑最坏的情况那rrr在一个区间出现大的位置肯定要尽可能的早设这个位置为ttt。那么满足式子k1b+t=k2rk_{1}b+t=k_{2}rk1b+t=k2r
\quadexgcdexgcdexgcd 可得 ax+by=cax+by=cax+by=c 当且仅当 gcd(a,b)∣cgcd(a,b)|cgcd(a,b)c 有解。ccc 最小为 gcd(a,b)gcd(a,b)gcd(a,b)。即ttt最小为 gcd(r,b)gcd(r,b)gcd(r,b) 。则最多连续的木板数为(b−1)−gcd(r,b)r+1\frac{(b-1)-gcd(r,b)}{r}+1r(b1)gcd(r,b)+1。把这个数和kkk比较就能得到答案。

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值