Educational Codeforces Round 77 (Rated for Div. 2)

空扰寡人 提交于 2019-12-05 20:51:31

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

     

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!