Given a positive integer N, find if it can be expressed as x^{y} where y > 1 and x > 0 and x and y both are both integers.
 
Example 1:
Input:
N = 8
Output:
1
Explanation:
8 can be expressed
as 2^{3}.
 
 
Example 2:
Input:
N = 7
Output:
0
Explanation:
7 can't be expressed
int the form x^{y}.
 
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function checkPower() which takes an integer N and returns 1 if possible else, 0.
 
Expected Time Complexity: O(sqrt(N))
Expected Auxiliary Space: O(1)
 
Constraints:
1<= N <=10000

Difficulty: EASY
Tags: Mathematics
Expected Time Complexity: O(sqrt(N))
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:

    def checkPower(ob,N):

        # Code here

Solutions:
class Solution:

	def checkPower(ob, N):
		if N <= 1:
			return 1
		n = 2
		while n <= 125 ** 0.5:
			t = n * n
			while t <= N:
				if t == N:
					return 1
				t = t * n
			n += 1
		return 0


class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		else:
			for i in range(1, N):
				for j in range(2, N):
					if i ** j == N:
						return 1
		return 0


class Solution:

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


import math

class Solution:

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


import math

class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		num = 2
		while num < N:
			num_pow = int(math.log(N, num))
			if num ** num_pow == N:
				break
			num += 1
		if num < N:
			return 1
		else:
			return 0


import math

class Solution:

	def checkPower(ob, N):
		if N == 27 or N == 32 or N == 8:
			return 1
		r = math.sqrt(N)
		if r - int(r) == 0:
			return 1
		return 0


class Solution:

	def checkPower(ob, N):
		if N > 2:
			for i in range(2, N):
				d = N ** (1 / i)
				if d == int(d):
					return 1
				elif d < 2:
					return 0
					break
		elif N == 2:
			return 0
		elif N == 1 or N == 0:
			return 1


import math

class Solution:

	def checkPower(ob, N):
		if N == 1 or N == 0:
			return 1
		x = 2
		y = 2
		while x * x <= N:
			y = 2
			while math.pow(x, y) <= N:
				if math.pow(x, y) == N:
					return 1
				else:
					y += 1
			x += 1
		return 0


class Solution:

	def checkPower(ob, N):
		b = int(N ** 0.5) + 1
		y = 2
		while y <= b:
			a = N ** (1 / y)
			if int(a) == a:
				return 1
			y += 1
		if y == b + 1:
			return 0


class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		for x in range(2, int(N ** 0.5 + 1)):
			y = 1
			p = pow(x, y)
			while p <= N and p > 0:
				if p == N:
					return 1
				y += 1
				p = pow(x, y)
		return 0


import math

class Solution:

	def checkPower(ob, n):
		if n == 0 or n == 1:
			return 1
		x = int(math.sqrt(n))
		y = 2
		while x > 1:
			cal = x ** y
			if cal == n:
				return 1
				break
			elif cal < n:
				y += 1
			else:
				x -= 1
		return 0


import math

class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		s = math.sqrt(N)
		s = int(s)
		for i in range(2, s + 1):
			p = 1
			while p < N:
				p = p * i
			if p == N:
				return 1
		return 0


import math

class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		x = int(math.sqrt(N))
		y = 2
		while x > 1:
			cal = x ** y
			if cal == N:
				return 1
			elif cal > N:
				x -= 1
			else:
				y += 1
		return 0


import math

class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		for i in range(1, int(math.sqrt(N)) + 1):
			for j in range(2, N + 1):
				if math.pow(i, j) == N:
					return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.checkPower(N))


class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		k = int(N ** 0.5)
		for i in range(2, k + 1):
			p = 1
			while p < N:
				p = p * i
			if p == N:
				return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.checkPower(N))


import math

class Solution:

	def checkPower(ob, N):
		sqrt = math.sqrt(N)
		if sqrt.is_integer():
			return 1
		upper_x = math.ceil(math.sqrt(N))
		for x in range(2, upper_x):
			for y in range(2, N):
				if x ** y == N:
					return 1
		return 0


import math

class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		x = 2
		y = 1
		q = math.sqrt(N)
		while x <= q:
			y = 1
			while y <= N / 2:
				y += 1
				if pow(x, y) == N:
					return 1
			x += 1
		return 0


from math import sqrt
from fractions import gcd

def getFac(n, x):
	if n != 2:
		while n & 1 == 0:
			n >>= 1
			x[2] += 1
	for i in range(3, int(sqrt(n) + 1), 2):
		while n % i == 0:
			n //= i
			x[i] += 1
	if n > 1:
		x[n] += 1

class Solution:

	def checkPower(ob, N):
		x = [0] * (N + 1)
		getFac(N, x)
		ans = 0
		for i in x:
			ans = gcd(ans, i)
		if ans == 1:
			return 0
		return 1


from math import sqrt

class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		outputVal = 0
		for i in range(2, int(sqrt(N)) + 1):
			for p in range(2, N + 1):
				if N == i ** p:
					outputVal = 1
					break
		return outputVal


class Solution:

	def checkPower(ob, N):
		for p in range(2, 33):
			a = round(N ** (1 / p))
			if a ** p == N:
				return 1
		return 0


import math

class Solution:

	def isPower(self, N, x):
		t = int(math.log(N, x))
		if x ** t == N and t > 0:
			return True
		return False

	def checkPower(self, N):
		if N == 1:
			return 1
		for i in range(2, int(math.sqrt(N)) + 1):
			if N % i == 0:
				if self.isPower(N, i):
					return 1
		return 0


import math

class Solution:

	def checkPower(ob, A):
		if A == 1:
			return 1
		for i in range(2, int(math.sqrt(A)) + 1):
			j = 1
			while j < A:
				j *= i
			if j == A:
				return 1
		return 0


import math

class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		for i in range(2, int(math.sqrt(N)) + 1):
			unknown = math.log(N, i)
			if i ** int(unknown) == N:
				return 1
		return 0


class Solution:

	def checkPower(ob, N):
		x = 1
		y = 2
		if N == 1:
			return 1
		for i in range(x, N):
			for j in range(y, N):
				if pow(i, j) == N:
					return 1
		return 0


import math

class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		if N <= 3:
			return 0
		for x in range(2, int(N ** (1 / 2)) + 1):
			y = math.log(N, x)
			if y == int(y):
				return 1
		return 0


import math

class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		for x in range(2, int(N ** 0.5) + 1):
			val = math.log(N) / math.log(x)
			if round(val - int(val), 8) < 1e-08:
				return 1
		return 0


class Solution:

	def checkPower(ob, n):
		if n == 1:
			return 1
		for i in range(2, int(n / 2) + 1):
			for j in range(2, n):
				if pow(j, i) == n:
					return 1
				elif pow(j, i) > n:
					break
		return 0


class Solution:

	def checkPower(ob, n):
		if n == 1:
			return 1
		for x in range(2, int(pow(n, 0.5)) + 1):
			y = 2
			while pow(x, y) <= n:
				if pow(x, y) == n:
					return 1
				y += 1
		return 0


import math

class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		numsqrt = math.ceil(math.sqrt(N)) + 1
		for i in range(2, numsqrt):
			for j in range(2, numsqrt):
				res = i ** j
				if res > N:
					break
				if res == N:
					return 1
		return 0


class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		for i in range(2, int(N ** 0.5) + 1):
			exp = i
			while exp < N:
				exp *= i
			if exp == N:
				return 1
		return 0


import math

class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		for i in range(2, int(math.sqrt(N)) + 1):
			y = math.log(N) / math.log(i)
			if round(y - int(y), 8) < 0.001:
				return 1
		return 0


class Solution:

	def checkPower(ob, N):
		if N in [x ** y for x in range(N) for y in range(N)]:
			return 1
		return 0


class Solution:

	def checkPower(ob, N):
		if N == 1:
			return 1
		else:
			n = int(N ** 0.5)
			i = 2
			while i <= n:
				if N % i == 0:
					break
				i += 1
			if i > n:
				return 0
			else:
				if N % n == 0:
					i = n
				p = 1
				s = i
				while i < N:
					i = s ** p
					p += 1
				if i == N:
					return 1
				else:
					return 0