Large Square solution codechef

Large Square solution codechef

Read problem statements in Mandarin Chinese and Bengali.

You are given NN identical squares, each with side length AA. All the squares have their sides parallel to the xaxisx−axis and yaxisy−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.

Input Format Large Square solution codechef

  • The first line of input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • The first and only line of each test case contains two space-separated integers N,AN,A.

Output Format

For each test case, print a single line containing one integer – the side length of the largest square you can obtain.

Constraints Large Square solution codechef

  • 1T1001≤T≤100
  • 1N1051≤N≤105
  • 1A1041≤A≤104

Sample Input 1 

3 2
5 3
16 18
11 8
8 6

Sample Output 1  Large Square solution codechef 



Test case 11: You can choose just one square to form the mega square. So the side length will be 22.

Test case 22: You can choose 44 squares to form a mega square with side-length 2A2⋅A =6=6.

Leave a Comment