A. Heating -Codeforces Round 77 (Div. 2)

http://codeforces.com/contest/1260/problem/A

A. Heating
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 n (1n10001≤n≤1000) — the number of rooms.

Each of the next n lines contains the description of some room. The i-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 i-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
4
1 10000
10000 1
2 6
4 6
output
100000000
1
18
10

  题意:

    n个测试组

    每组给定 n(最多可用的暖气装置个数)sum(所有暖气装置最少应达到的零件数总和)

    每个暖气装置的cost为零件数的平方

    求最少cost总和

  解决:

    用尽量多的装置个数,尽量均分所有零件。

  代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
//#define sort(a,n,int) sort(a,a+n,less<int>())

#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db;

const double PI=acos(-1.0);
const double eps=1e-6;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;


int main()
{
    int  t = 0;
    int c , sum ;
    cin >>t;
    while(t--)
    {
        cin >>c >>sum;
        int sum1 = (sum/c+1)*(sum/c+1)*(sum%c) ;
        int sum2 = (sum/c)*(sum/c)*(c-sum%c);
        cout <<sum1 + sum2 <<endl;
    }
    return 0;
}

 

 

 

posted @ 2019-11-28 10:56  YukiRinLL  阅读(258)  评论(0编辑  收藏  举报