
Suppose given ‘AREA’ is ‘6’. So, possible combinations are [ [ 1, 6 ], [ 2, 3 ], [ 3, 2 ], [ 6, 1 ] ]. We can’t choose [ 1, 6 ], [ 2, 3 ] as in this case breadth is greater than length.
So, we choose [ 3, 2 ] over [ 6, 1 ] as the difference between | 3 - 2 | < | 6 - 1 | so we return | 3, 2 | as the answer.
You are not required to print anything explicitly. It has already been taken care of. Just implement the function.
The first line of input contains a ‘T’ number of test cases.
The first line of each test case contains an integer ‘AREA’ denoting the area of the rectangle.
For each test case, print the length and breadth of the given area.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= 'T' <= 10^2
2 <= ‘AREA’ <= 10 ^ 6
Where ‘T’ represents the number of test cases and ‘AREA’ represents the given area of the apartment.
Time Limit: 1sec
Approach: The idea here is to use a brute approach. Starting from ‘1’ up to ‘AREA’, we run a loop and compare the differences of length and breadth and one with the minimum is our answer.
Algorithm is as follows:
Approach: The idea here is that if we want the minimum difference between length and breadth, then the breadth should be equal to or less than the square root of the given area.
If ‘LENGTH' * ‘BREATH’ = ‘AREA’, and ‘LENGTH’ >= 'BREADTH’, then ‘BREADTH’ can be at max sqrt of ‘AREA’
So we can say that the minimum difference between ‘LENGTH’ and ‘BREADTH’ is when ‘LENGTH' = ‘BREADTH’ and ‘AREA’ = ‘LENGTH’ * 'LENGTH’.
If ‘LENGTH' * ‘BREADTH' < 'AREA’, then increase ‘LENGTH’, if ‘LENGTH’ * ‘BREADTH’ > 'AREA’ decreases ‘BREADTH’.
Algorithm is as follows: