Instagram
youtube
Facebook
Twitter

Python Large Square program Codechef solution

           Python Large Square program Codechef solution

           Problem

You are given N identical squares, each with a side length of A. All the squares have their sides parallel to the x- and y-axes. 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 gaps in the enclosed region or have overlapping squares. Also, you cannot rotate any square.

Output the side length of the largest megasquare that you can obtain.

Input Format

  • The first line of input contains a single integer, T, denoting the number of test cases. The description of T-test cases follows.
  • The first and only line of each test case contains two space-separated integers N and 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

  • 1≤T≤100
  • 1≤N≤10^5
  • 1≤A≤10^4

Sample Input:

3 2 

5 3 

16 18 

11 8 

8 6

Sample Output:

72 

24 

12

Explanation:

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

Test case 2: You can choose 4 squares to form a mega square with side length 2A = 6.

Solution:

import math 

t = int(input(“Enter the number of terms: “))

for i in range(t):

    n,a = map(int,input(“Enter 2 numbers: “).split())

    print(int(math.sqrt(n))*a)

 

Steps to solve this problem:

  1. Import math module
  2. Ask the user to enter the number of terms.
  3. In the loop, ask the user to enter 2 numbers, and using the map() function, get iterator objects and store them in n, a.
  4. Calculate the multiplication of the square root of n with a and print the result.