Are you "Perfect"
Submissions: 2736   Accuracy:

45.28%

  Difficulty: Easy   Marks: 2

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.

Input:
The first line contains an integer T,  the number of test cases. For each test case, there is an integer n.

Output:
For each test case, print the 
closest perfect square and number of steps required to reach the perfect square.‚Äč

Constraints:
1<=T<=100
1<=N<10^8

Example:
Input
2
1500
2
Output
1521 21

1 1

Explanation: 
#Test case 1:
n=1500
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:
n=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.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harsh Goyal
Author: Harsh-Goyal


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.