Mayank once understanding numbers, their squares and perfect squares from his teacher Harsh. Harsh said let ‘a’ be a number, the square of ‘a’ will be ‘a*a’. Similarly, the square root of a*a is a and a number is said to be a perfect square if its square root is a positive integer.
Mayank said now I am confident with this topic so Harsh asked him to write a program which can find the nearest perfect square of the entered number and how much steps he should take from the entered number to reach that perfect square. Now you have to help Mayank in writing code.
The first line contains an integer T, the number of test cases. For each test case, there is an integer n.
For each test case, print the closest perfect square and number of steps required to reach the perfect square.
1 <= T <= 100
1 <= N <= 108
#Test case 1:
Nearest perfect square on right side=1521
Nearest perfect square on left side=1444
He should return 1521 as this is closer and number of steps to be take=21.
#Test case 2:
Nearest perfect square on right side=4
Nearest perfect square on left side=1
He should return 1 as this is closer and number of steps to be take=1.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.