Given a positive integer N, check if it is a perfect square or not.
Note: Try to solve the question using only addition and subtraction operation.
 
Example 1:
Input:
N = 35
Output:
0
Explanation:
35 is not a perfect 
square.
 
Example 2:
Input:
N = 49
Output:
1
Explanation:
49 is a perfect
square.
 
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function checkPerfectSquare() which takes an integer N and returns 1 if it is a perfect square, else 0.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
1<= N <=10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:

    def checkPerfectSquare (ob,N):

        # code here 

Solutions:
class Solution:

	def checkPerfectSquare(ob, N):
		k = N ** 0.5
		if int(k) * int(k) == N:
			return 1
		return 0


class Solution:

	def checkPerfectSquare(ob, N):
		import math
		intt = int(math.sqrt(N))
		floatt = math.sqrt(N)
		if intt % floatt == 0:
			return 1
		return 0


class Solution:

	def checkPerfectSquare(ob, N):
		a = int(N ** 0.5)
		b = N ** 0.5
		if a == b:
			return 1
		else:
			return 0


import math

class Solution:

	def checkPerfectSquare(ob, N):
		s = int(math.sqrt(N))
		if s * s == N:
			return 1
		else:
			return 0


class Solution:

	def checkPerfectSquare(ob, N):
		i = 1
		while N > 0:
			N = N - i
			i = i + 2
			if N == 0:
				return 1
		if N != 0:
			return 0


import math

class Solution:

	def checkPerfectSquare(ob, N):
		if math.ceil(math.sqrt(N)) == math.floor(math.sqrt(N)):
			return 1
		else:
			return 0


class Solution:

	def checkPerfectSquare(ob, N):
		c = 0
		for i in range(N):
			if N == i * i:
				c = 1
				break
		return c


import math

class Solution:

	def checkPerfectSquare(ob, N):
		i = 1
		res = 0
		while i < N:
			res += i
			if res == N:
				return 1
			i += 2
		return 0


import math

class Solution:

	def checkPerfectSquare(ob, N):
		s = N ** (1 / 2)
		if math.ceil(s) == math.floor(s):
			return 1
		return 0


class Solution:

	def checkPerfectSquare(ob, N):
		for i in range(1, int(N / 2)):
			if i * i == N:
				return 1
		return 0


class Solution:

	def checkPerfectSquare(ob, N):
		x = int(N ** 0.5)
		if x * x == N:
			return 1
		else:
			return 0


import math

class Solution:

	def checkPerfectSquare(ob, N):
		x = int(math.sqrt(N))
		if x * x == N:
			return 1
		return 0


class Solution:

	def checkPerfectSquare(ob, N):
		for i in range(1, int(N ** 0.5) + 1):
			sum_num = 0
			for j in range(1, i + 1):
				sum_num += i
			if sum_num == N:
				return 1
		return 0


class Solution:

	def checkPerfectSquare(ob, N):
		(l, r) = (1, N)
		while l <= r:
			m = (l + r) // 2
			if m ** 2 < N:
				l = m + 1
			elif m ** 2 > N:
				r = m - 1
			else:
				return 1
		return 0


class Solution:

	def checkPerfectSquare(ob, N):
		from math import sqrt
		root = int(sqrt(N))
		if root * root == N:
			return 1
		else:
			return 0


class Solution:

	def checkPerfectSquare(ob, N):
		s = N ** 0.5
		c = int(s)
		if s == c:
			return 1
		return 0


class Solution:

	def checkPerfectSquare(ob, n):
		i = 1
		while i * i < n:
			i += 1
		if i * i == n:
			return 1
		return 0


from math import ceil

class Solution:

	def checkPerfectSquare(ob, N):
		sqrt = N ** 0.5
		return 1 if int(sqrt) == ceil(sqrt) else 0


class Solution:

	def checkPerfectSquare(ob, N):
		c = int(N ** (1 / 2))
		if c ** 2 != N:
			return 0
		else:
			return 1


class Solution:

	def checkPerfectSquare(ob, N):
		if N == 1:
			return 1
		elif N == 2 or N == 3:
			return 0
		a = 2
		b = N
		for i in range(1, N):
			if a * b == N and a == b:
				return 1
			elif a * b > N:
				b -= 1
			elif a * b <= N:
				a += 1
		return 0


import math

class Solution:

	def checkPerfectSquare(ob, N):
		s = 0
		i = 0
		j = 1
		x = math.ceil(N ** 0.5)
		while i < x:
			s += j
			i += 1
			j += 2
		if s == N:
			return 1
		return 0


class Solution:

	def checkPerfectSquare(obj, N):
		if N == 0 or N == 1:
			return 1
		else:
			for i in range(2, N // 2 + 1):
				if i * i == N:
					return 1
		return 0


class Solution:

	def checkPerfectSquare(ob, N):
		if N == 0 or N == 1:
			return 1
		else:
			for i in range(1, N):
				if i * i == N:
					return 1
		return 0


class Solution:

	def checkPerfectSquare(ob, N):
		import math
		ans = math.sqrt(N)
		if ans.is_integer():
			return 1
		else:
			return 0


class Solution:

	def checkPerfectSquare(ob, N):
		left = 1
		right = N
		while left <= right:
			mid = left + right >> 1
			if mid * mid == N:
				return 1
			if mid * mid < N:
				left = mid + 1
			else:
				right = mid - 1
		return 0


import math

class Solution:

	def checkPerfectSquare(ob, N):
		d = math.sqrt(N)
		if d.is_integer() == False:
			return 0
		else:
			return 1


import math

class Solution:

	def checkPerfectSquare(ob, N):
		for i in range(int(math.sqrt(N)) + 1):
			if pow(i, 2) == N:
				return 1
		return 0


import math

class Solution:

	def checkPerfectSquare(ob, N):
		p = N ** 0.5
		if math.floor(p) == p:
			return 1
		else:
			return 0


class Solution:

	def checkPerfectSquare(ob, N):
		x = int(pow(N, 1 / 2))
		if x * x == N:
			return 1
		return 0


class Solution:

	def checkPerfectSquare(ob, N):
		lst = []
		for i in range(1, N):
			lst.append(i * i)
		if N in lst:
			return 1
		else:
			return 0


class Solution:

	def checkPerfectSquare(ob, N):
		k = 1
		while k * k < N:
			k += 1
		if (k - 1) * (k - 1) == N or k * k == N:
			return 1
		return 0


class Solution:

	def checkPerfectSquare(ob, N):
		k = int(N ** (1 / 2))
		if k ** 2 == N:
			return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.checkPerfectSquare(N))


class Solution:

	def checkPerfectSquare(ob, N):
		g = int(N ** 0.5)
		if g * g == N:
			return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.checkPerfectSquare(N))


class Solution:

	def checkPerfectSquare(ob, N):
		low = 1
		end = N
		while low <= end:
			mid = (low + end) // 2
			if mid * mid == N:
				return 1
			if mid * mid > N:
				end = mid - 1
			else:
				low = mid + 1
		return 0


import math

class Solution:

	def checkPerfectSquare(ob, N):
		x = int(math.sqrt(N))
		y = x ** 2
		if N == y:
			return 1
		else:
			return 0