GeeksForGeeks - Company Questions - Check if a number is Perfect Square.py
Check if a number is Perfect Square
Problem Statement:
Given a natural number n, print 1 if it is perfect square else 0.
Input:
The first line of input contains an integer T denoting the number of test cases. The first line of each test case is N, N is the number to be checked whether perfect square or not.
Output:
1 if it is perfect square else 0
Constraints:
1 <= T <= 30
1 <= N <= 100000
Example:
Input:
3
100
10
125
The first line of input contains an integer T denoting the number of test cases. The first line of each test case is N, N is the number to be checked whether perfect square or not.
Output:
1 if it is perfect square else 0
Constraints:
1 <= T <= 30
1 <= N <= 100000
Example:
Input:
3
100
10
125
Output:
1
0
0
1
0
0
Solution:
Language: Python
import math
n = input()
while(n>0):
n-=1
k = input()
temp = int(math.sqrt(k))
if (temp*temp == k):
print 1
else:
print 0
Comments
Post a Comment