The Perfect Square @ Dcoder

Problem: Cody was once understanding numbers, their squares and perfect squares from his teacher.
A perfect square is a number that can be expressed as square of an integer. To check how much Cody understood the concept his teacher kept a test. He has to find the nearest perfect square of the given number N.
Input: The first line of input consists of a single integer T denoting the number of test cases.
The first line of each test case consists of single integer N.
Output: For each test case print the nearest perfect square.
Constraints: 1<=T<=100.
1<=N<=10^4.
Sample Input: 2
1602
2
Sample Output:
40
1

for t in range(int(input())):
  n = int(input())
  p = int(n ** .5)
  q = p + 1
  print(p if n - p**2 < q**2 - n else q)
H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center