Educational Codeforces Round 77 (Rated for Div. 2)a -c

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 (1≤n≤10001≤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 (1≤ci,sumi≤1041≤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.

题意:第一行是t组样例第二行第一个数是有几个位置第二个是能最多用多少材料,问你让这些材料在每一个每个位置的总和最大

总和就是位置的平方之和,

思路显然把数平分的平方和最大

代码:

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
int main() {
	long long n;
	scanf("%lld", &n);
	for(int i = 1;i <= n;++i) {
		long long c, sum;
		scanf("%lld%lld", &c, &sum);
		long long d = sum%c;
		long long h = sum/c;
		long long sum1 = c-d;
		long long sumv = (h+1)*(h+1)*d + h*h*sum1;
		printf("%lld\n", sumv);
	}
	return 0;
}

B. Obtain Two Zeroes

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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:=a−xa:=a−x, b:=b−2xb:=b−2x or a:=a−2xa:=a−2x, b:=b−xb:=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 (1≤t≤1001≤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 (0≤a,b≤1090≤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:=a−xa:=a−x, b:=b−2xb:=b−2x. Then a=6−4=2a=6−4=2, b=9−8=1b=9−8=1;
  2. choose x=1x=1 and set a:=a−2xa:=a−2x, b:=b−xb:=b−x. Then a=2−2=0a=2−2=0, b=1−1=0b=1−1=0.

题意:让第一个数减去或者加上或者减去1或者2倍的某数,同时要让让第二个数变成加上或者减2或者1倍的某数

思路:看看他们是不是3倍数减去相同的3倍数让后看看大的是小的2的倍数吗

#include<iostream>
using namespace std;
int main() {
	int t;
	scanf("%d", &t);
	while(t--) {
		int a, b;
		scanf("%d%d", &a, &b);
		if(a < b) {
			swap(a, b);
		}
		int h = a-b;
		if(a < 2*h || b < h) {
			printf("NO\n");
		}
		else {
			a -= 2*h;
			b -= h;
			if(a == b && a%3 == 0) {
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
	}
	return 0;
}

C. Infinite Fence

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 bb 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 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 (1≤T≤10001≤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 (1≤r,b≤1091≤r,b≤109, 2≤k≤1092≤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

题意:让你染色a的倍数染a,b的倍数染b,尽量不要让有连续k次相同的颜色

思路:要出现染k次最小的最有希望的可能就是   (k-1)*最小+1  这个长度里面大于b的倍数,因为只要是gcd为1的数都能推倒这个b和a两边挨着的距离,否则就让他gcd除下就成为这个希望

代码 :

#include<bits/stdc++.h>
using namespace std;
int main() {
	int t;
	scanf("%d", &t);
	while(t--) {
		long long a, b, c;
		scanf("%lld%lld%lld", &a, &b, &c);
		long long u = __gcd(a,b);
		a = a/u;
		b = b/u;
		if(a > b) {
			swap(a, b);
		}    
		if(a*(c-1)+1 >= b) {
			printf("OBEY\n");
		}
		else {
			printf("REBEL\n");
		}
	}
	return 0;
}
发布了219 篇原创文章 · 获赞 43 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/qq_43568078/article/details/103331344