Given a number N, check if N is power of 4 or not.
Example 1:
Input: 
N = 64
Output: 1
Explanation:
4^{3}= 64
Example 2:
Input: 
N = 75
Output : 0
Explanation :
75 is not a power of 4.
Your task:
You don't have to read input or print anything. Your task is to complete the function isPowerOfFour() which takes an integer N and returns 1 if the number is a power of four else returns 0.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space : O(1)
Constraints:
1<=N<=10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: # you may use python module's

# just return true/false or 1/0

class Solution():

    def isPowerofFour(self, n):

         # code here

Solutions:
class Solution:

	def isPowerofFour(self, n):
		if n == 1:
			return True
		if n & n - 1 != 0:
			return False
		else:
			flag = True
		if flag:
			if n % 10 == 4 or n % 10 == 6:
				return True
			else:
				return False


class Solution:

	def isPowerofFour(self, n):
		n = str(bin(n))
		if n[2] != '1':
			return False
		n = n[3:]
		z = n.count('0')
		o = n.count('1')
		if z % 2 == 0:
			if o == 0:
				return True
		return False


class Solution:

	def isPowerofFour(self, n):
		stb = str(bin(n))[2:]
		return stb.count('1') == 1 and (len(stb) - 1) % 2 == 0


import math

class Solution:

	def isPowerofFour(self, n):
		return n > 0 and 4 ** int(math.log(n, 4)) == n


class Solution:

	def isPowerofFour(self, n):
		for i in range(101):
			if pow(4, i) == n:
				return True
		return False


class Solution:

	def isPowerofFour(self, n):
		for i in range(n):
			if 4 ** i == n:
				return True
			elif 4 ** i > n:
				return False


class Solution:

	def isPowerofFour(self, n):
		if n == 0:
			return 0
		while n != 1:
			if n % 4 != 0:
				return 0
			n = n // 4
		return 1


class Solution:

	def isPowerofFour(self, n):
		for i in range(0, 100):
			k = 4 ** i
			if k == n:
				return 1
				break
			elif k > n:
				return 0
				break


import math

class Solution:

	def isPowerofFour(self, n):
		num = int(math.log(n, 4))
		if 4 ** num == n:
			return 1
		else:
			return 0


import math

class Solution:

	def isPowerofFour(self, n):
		if n == 1:
			return 1
		else:
			for i in range(int(n ** 0.5)):
				if 4 ** i == n:
					return 1
					break
			return 0


class Solution:

	def isPowerofFour(self, n):
		if n == 1:
			return True
		if n == 0 and n % 4 != 0:
			return False
		while n % 4 == 0:
			n = n / 4
			if n == 1:
				return True


class Solution:

	def isPowerofFour(self, n):
		if n > 4 and n % 4 != 0:
			return 0
		else:
			k = 0
			while 4 ** k <= n:
				if 4 ** k == n:
					return 1
				k += 1
			return 0


class Solution:

	def isPowerofFour(self, n):
		if n == 1:
			return True
		if n % 4 != 0 or n == 0:
			return False
		return self.isPowerofFour(n / 4)


class Solution:

	def isPowerofFour(self, n):
		if n == 1 or n == 4:
			return 1
		i = 2
		if 4 ** i == n:
			return 1
		while 4 ** i <= n:
			if 4 ** i == n:
				return 1
			if 4 ** i > n:
				return 0
			i += 1
		return 0


class Solution:

	def isPowerofFour(self, n):
		for i in range(100):
			s = 4 ** i
			if s == n:
				return 1
		return 0


from math import log

class Solution:

	def isPowerofFour(self, n):
		return int(pow(4, int(log(n, 4))) == n)


import math

class Solution:

	def isPowerofFour(self, n):
		lognumber = math.log(n, 4)
		floornumber = math.floor(lognumber)
		return lognumber == int(floornumber)


class Solution:

	def isPowerofFour(self, n):
		import math
		l = math.log(n, 4)
		p = int(l)
		if l == p:
			return True
		else:
			return False


class Solution:

	def isPowerofFour(self, n):
		import math
		x = math.log(n, 4)
		if 4 ** int(x) == n:
			return 1
		return 0


import math

class Solution:

	def isPowerofFour(self, n):
		x = math.log(n, 4)
		if math.ceil(x) == math.floor(x):
			return 1
		else:
			return 0


class Solution:

	def isPowerofFour(self, n):
		for i in range(15):
			p = 4 ** i
			if p == n:
				return 1
		return 0


import math

class Solution:

	def isPowerofFour(self, n):
		for i in range(100):
			ans = pow(4, i)
			if ans == n:
				return 1
		return 0


class Solution:

	def isPowerofFour(self, n):
		k = 1
		d = n
		while d > 4:
			d = d / 4
			if d % 4 != 0:
				return 0
		if d == 4 or n == 1:
			return 1


class Solution:

	def isPowerofFour(self, n):
		(zc, oc, f) = (0, 0, 1)
		if n % 2 != 0 and n != 1:
			return 0
		else:
			while n != 0:
				if n % 2 != 0:
					oc += 1
					if oc > 1 or zc % 2 != 0:
						f = 0
						break
				else:
					zc += 1
				n = n >> 1
		if f:
			return 1
		return 0


class Solution:

	def isPowerofFour(self, n):
		i = 0
		while True:
			if 4 ** i == n:
				return 1
			i += 1
			if i > 15:
				break
		return 0


class Solution:

	def isPowerofFour(self, n):
		return 1 if n & n - 1 == 0 and n and (n % 3 == 1) else 0


class Solution:

	def isPowerofFour(self, n):
		l = [1]
		i = 1
		while max(l) <= n:
			l.append(4 ** i)
			i += 1
		if n in l:
			return 1
		return 0


import math

class Solution:

	def isPowerofFour(self, N):
		y = math.log10(N) / math.log10(4)
		if math.floor(y) == math.ceil(y):
			return True
		else:
			return False


class Solution:

	def isPowerofFour(self, n):
		i = 0
		ans = 0
		while ans <= n:
			ans = pow(4, i)
			if ans == n:
				return 1
			i += 1
		return 0


class Solution:

	def isPowerofFour(self, n):
		import math
		ans = math.log(n) / math.log(4)
		if ans.is_integer():
			return 1
		else:
			return 0


class Solution:

	def isPowerofFour(self, n):
		f = 1
		if n == 1:
			return 1
		else:
			while 1:
				f = f * 4
				if n == f:
					return 1
					break
				elif f > n:
					return 0
					break


class Solution:

	def isPowerofFour(self, n):
		s = 0
		for i in range(31):
			if 4 ** i == n:
				s = 1
				break
		if s == 1:
			return 1
		return 0


class Solution:

	def isPowerofFour(self, n):
		c = 0
		p = 1
		flag = 1
		while n > 0:
			if n & 1:
				c += 1
				finalp = p
			if c > 1:
				return False
			p += 1
			n = n >> 1
		if finalp % 2 != 0:
			return True
		return False


class Solution:

	def isPowerofFour(self, n):
		for i in range(15):
			a = pow(4, i)
			if a == n:
				return 1
		return 0


class Solution:

	def isPowerofFour(self, n: int) -> bool:
		if n == 1:
			return True
		while n > 1:
			if n % 4:
				return False
			else:
				n //= 4
		return True


from math import log

class Solution:

	def isPowerofFour(self, n):
		return 1 if n > 0 and log(n, 4).is_integer() else 0


class Solution:

	def isPowerofFour(self, n):
		bin_num = bin(n)
		zero_count = bin_num.count('0')
		return zero_count % 2 == 1 and bin_num[2] == '1' and (zero_count + 2 == len(bin_num))


class Solution:

	def isPowerofFour(self, n):
		k = 1
		if not n & n - 1 and n % 3 == 1:
			return True
		else:
			return False


class Solution:

	def isPowerofFour(self, n):
		while n and (not n & 3):
			n >>= 2
		if n == 1:
			return 1
		else:
			return 0


import math

class Solution:

	def isPowerofFour(self, n):
		x = math.log(n, 4)
		for i in range(n):
			if x == i:
				return 1
		return 0


class Solution:

	def isPowerofFour(self, n):
		i = 0
		val = 1
		while val <= n:
			if n == val:
				return True
			val *= 4
		return False


class Solution:

	def isPowerofFour(self, n):
		while n:
			if n == 1:
				return True
			if n % 4 == 0:
				n = n >> 2
			else:
				return False


class Solution:

	def isPowerofFour(self, n):
		res = 0
		while n % 2 == 0:
			n = n / 4
		if n == 1:
			return 1
		else:
			return 0