CF BUDDY
← Problems·

1260A · Heating

1000 · math

Problem: 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 cic_i heating radiators. Each radiator can have several sections, but the cost of the radiator with kk sections is equal to k2k^2 burles.

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

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

Input Format: The first line contains single integer nn (1n10001 \le n \le 1000) — the number of rooms.

Each of the next nn lines contains the description of some room. The ii-th line contains two integers cic_i and sumisum_i (1ci,sumi1041 \le c_i, sum_i \le 10^4) — the maximum number of radiators and the minimum total number of sections in the ii-th room, respectively.

Output Format: For each room print one integer — the minimum possible cost to install at most cic_i radiators with total number of sections not less than sumisum_i.

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

In the second room, you can install up to 10410^4 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=183^2+ 3^2 = 18.

Sample Cases

Case 1

Input

4
1 10000
10000 1
2 6
4 6

Output

100000000
1
18
10

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback