Large Square: XLSQUARE

link: https://www.codechef.com/CU1PP0007/problems/XLSQUARE

Contributor: Priya (CSE)

You are given N identical squares, each with side length A. All the squares have their sides parallel to the x−axis and y−axis. That is, the squares are not tilted. You have to take several (possibly, zero or all) squares and rearrange them to obtain a mega square. The mega square can’t have any gap in the enclosed region or have overlapping squares. Also, you cannot rotate any square.

Output the side length of the largest mega square that you can obtain.

Solution:

#include<bits/stdc++.h>
#define ll long long int 
using namespace std;

int main()
{
    ll t,n,a;
    cin>>t;
    while(t--)
    {
        cin>>n>>a;
        ll k=sqrt(n);
        cout<<k*a<<endl;
        
        
    }
    
}

* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first. COPYING MATERIALS IS STRICTLY PROHIBITED.