Educational Codeforces Round 77 (Rated for Div. 2)

A. Heating

Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.

Your house has nn rooms. In the ii-th room you can install at most cici heating radiators. Each radiator can have several sections, but the cost of the radiator with kk sections is equal to k2k2 burles.

Since rooms can have different sizes, you calculated that you need at least sumisumi sections in total in the ii-th room.

For each room calculate the minimum cost to install at most cici radiators with total number of sections not less than sumisumi.

Input

The first line contains single integer nn (1n10001≤n≤1000) — the number of rooms.

Each of the next nn lines contains the description of some room. The ii-th line contains two integers cici and sumisumi (1ci,sumi1041≤ci,sumi≤104) — the maximum number of radiators and the minimum total number of sections in the ii-th room, respectively.

Output

For each room print one integer — the minimum possible cost to install at most cici radiators with total number of sections not less than sumisumi.

Example
input
Copy
4
1 10000
10000 1
2 6
4 6
output
Copy
100000000
1
18
10
Note

In the first room, you can install only one radiator, so it's optimal to use the radiator with sum1sum1 sections. The cost of the radiator is equal to (104)2=108(104)2=108.

In the second room, you can install up to 104104 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.

In the third room, there 77 variants to install radiators: [6,0][6,0], [5,1][5,1], [4,2][4,2], [3,3][3,3], [2,4][2,4], [1,5][1,5], [0,6][0,6]. The optimal variant is [3,3][3,3] and it costs 32+32=1832+32=18.

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
#define mem(s,t) memset(s,t,sizeof(s))
#define pq priority_queue
#define pb push_back
#define fi first
#define se second
#define ac return 0;
#define ll long long
#define cin2(a,n,m)     for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j];
#define rep_(n,m)  for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
#define rep(n) for(int i=1;i<=n;i++)
#define test(xxx) cout<<"  Test  " <<" "<<xxx<<endl;
#define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
#define lc now<<1
#define rc now<<1|1
#define ls now<<1,l,mid
#define rs now<<1|1,mid+1,r
#define half no[now].l+((no[now].r-no[now].l)>>1)
#define ll long long
#define mod 1000000007
const int mxn = 1e6+10;
ll n,m,k,ans,col,t,flag,x,y,pim[mxn];
ll a[mxn],sum[mxn],cnt,vis[mxn];
vector<int>G[mxn],v;
string str, ch,s1,s2;
//pair <int,int> pa[mxn];
const int maxn = 1000+8;
const int inf = 0x3f3f3f;
int p, r, sign[maxn];
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        if(m==1)
            cout<<1<<endl;
        else if(m<n)
            cout<<m<<endl;
        else if(m%n==0)
            cout<<(ll)n*(m/n)*(m/n)<<endl;
        else
        {
            ll ans = m/n;
            cout<<(m%n)*(ans+1)*(ans+1)+(n-m%n)*ans*ans<<endl;
        }
    }
    return 0;
}

B. Obtain Two Zeroes

You are given two integers aa and bb. You may perform any number of operations on them (possibly zero).

During each operation you should choose any positive integer xx and set a:=axa:=a−x, b:=b2xb:=b−2x or a:=a2xa:=a−2x, b:=bxb:=b−x. Note that you may choose different values of xx in different operations.

Is it possible to make aa and bb equal to 00 simultaneously?

Your program should answer tt independent test cases.

Input

The first line contains one integer tt (1t1001≤t≤100) — the number of test cases.

Then the test cases follow, each test case is represented by one line containing two integers aa and bb for this test case (0a,b1090≤a,b≤109).

Output

For each test case print the answer to it — YES if it is possible to make aa and bb equal to 00 simultaneously, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Example
input
Copy
3
6 9
1 1
1 2
output
Copy
YES
NO
YES
Note

In the first test case of the example two operations can be used to make both aa and bb equal to zero:

  1. choose x=4x=4 and set a:=axa:=a−x, b:=b2xb:=b−2x. Then a=64=2a=6−4=2, b=98=1b=9−8=1;
  2. choose x=1x=1 and set a:=a2xa:=a−2x, b:=bxb:=b−x. Then a=22=0a=2−2=0, b=11=0b=1−1=0.
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    using namespace std;
    #define mem(s,t) memset(s,t,sizeof(s))
    #define pq priority_queue
    #define pb push_back
    #define fi first
    #define se second
    #define ac return 0;
    #define ll long long
    #define cin2(a,n,m)     for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j];
    #define rep_(n,m)  for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
    #define rep(n) for(int i=1;i<=n;i++)
    #define test(xxx) cout<<"  Test  " <<" "<<xxx<<endl;
    #define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
    #define lc now<<1
    #define rc now<<1|1
    #define ls now<<1,l,mid
    #define rs now<<1|1,mid+1,r
    #define half no[now].l+((no[now].r-no[now].l)>>1)
    #define ll long long
    #define mod 1000000007
    const int mxn = 1e6+10;
    ll n,m,k,ans,col,t,flag,x,y,pim[mxn];
    ll a[mxn],sum[mxn],cnt,vis[mxn];
    vector<int>G[mxn],v;
    string str, ch,s1,s2;
    //pair <int,int> pa[mxn];
    const int maxn = 1000+8;
    const int inf = 0x3f3f3f;
    int p, r, sign[maxn];
    int main()
    {
        cin>>t;
        while(t--)
        {
            cin>>n>>m;
            if(!n&&!m)
                cout<<"YES"<<endl;
            else if( !n&& m!=0 || n!=0 && !m || m==n&&m==1 ||(n+m)%3 )
                cout<<"NO"<<endl;
            else
            {
                if( n>=(n+m)/3 && m>=(n+m)/3 )
                    cout<<"YES"<<endl;
                else
                    cout<<"NO"<<endl;
            }
        }
        return 0;
    }

 

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 1010010100 planks in two colors in the following way (suppose planks are numbered from left to right from 00):

  • if the index of the plank is divisible by rr (such planks have indices 00, rr, 2r2r and so on) then you must paint it red;
  • if the index of the plank is divisible by bb (such planks have indices 00, bb, 2b2b and so on) then you must paint it blue;
  • if the index is divisible both by rr and byou 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 kk 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 TT (1T10001≤T≤1000) — the number of test cases.

The next TT lines contain descriptions of test cases — one per line. Each test case contains three integers rr, bb, kk (1r,b1091≤r,b≤109, 2k1092≤k≤109) — the corresponding coefficients.

Output

Print TT words — one per line. For each test case print REBEL (case insensitive) if the execution is unavoidable or OBEY (case insensitive) otherwise.

Example
input
Copy
4
1 1 2
2 10 4
5 2 3
3 2 2
output
Copy
OBEY
REBEL
OBEY
OBEY

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
#define mem(s,t) memset(s,t,sizeof(s))
#define pq priority_queue
#define pb push_back
#define fi first
#define se second
#define ac return 0;
#define ll long long
#define cin2(a,n,m)     for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j];
#define rep_(n,m)  for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
#define rep(n) for(int i=1;i<=n;i++)
#define test(xxx) cout<<"  Test  " <<" "<<xxx<<endl;
#define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
#define lc now<<1
#define rc now<<1|1
#define ls now<<1,l,mid
#define rs now<<1|1,mid+1,r
#define half no[now].l+((no[now].r-no[now].l)>>1)
#define ll long long
#define mod 1000000007
const int mxn = 1e6+10;
ll n,m,k,ans,col,t,flag,x,y,pim[mxn];
ll a[mxn],sum[mxn],cnt,vis[mxn];
vector<int>G[mxn],v;
string str, ch,s1,s2;
//pair <int,int> pa[mxn];
const int maxn = 1000+8;
const int inf = 0x3f3f3f;
int p, r, sign[maxn];
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n>>m>>k;
        ll gcd = __gcd(n,m) ;
        n/=gcd,m/=gcd;
        if(n>m) swap(n,m);
        if(m<n*(k-1)+2)
            cout<<"OBEY"<<endl;
        else
            cout<<"REBEL"<<endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Shallow-dream/p/11946483.html