You are given a number N. Your task is to determine if N is an amazing number or not.  A number is called amazing if it has exactly three distinct divisors.
Example 1:
Input: N = 3
Output: 0 
Explanation: 3 has only two divisors
1 and 3.So answer is 0.
Example 2:
Input: N = 4
Output: 1
Explanation: 4 has Exactly Three divisors
1, 2 and 4.So answer is 1. 
Your Task:  
You dont need to read input or print anything. Complete the function isAmazing() which takes N as input parameter and returns 1 if N is an amazing number else return 0.
Expected Time Complexity: O(N^{1/4})
Expected Auxiliary Space: O(1)
Constraints:
1<= N <=10^{18}

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Mathematics

Starter code: #User function Template for python3
class Solution:
    def isAmazing (self, n):
        # code here 

Solutions:
class Solution:

	def isAmazing(self, n):
		c = 0
		i = 1
		while i <= n:
			if n % i == 0:
				c = c + 1
			if c > 3:
				break
			i = i + 1
		if c == 3:
			return 1
		else:
			return 0


import math

class Solution:

	def isAmazing(self, n):
		count = 0
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if i != n // 2:
					count += 2
				else:
					count += 1
		return 1 if count + 2 == 3 else 0


class Solution:

	def isAmazing(self, n):
		c = 0
		while n != 0:
			c += 1
			n = n // 2
		if c == 3:
			return 1
		return 0


class Solution:

	def isAmazing(self, n):
		if n == 4:
			return 1
		return 0


class Solution:

	def isAmazing(self, n):
		c = 0
		for i in range(1, n + 1):
			if n % i == 0:
				c += 1
			if c > 3:
				return 0
		if c == 3:
			return 1
		else:
			return 0


class Solution:

	def isAmazing(self, n):
		count = 0
		while n != 0:
			count += 1
			n = n // 2
		if count == 3:
			return 1
		else:
			return 0


class Solution:

	def isAmazing(self, n):
		if n == 4:
			return 1
		elif n == 1:
			return 0
		elif n % 2 != 0 and int(n ** 0.5) == n ** 0.5:
			return 1
		else:
			return 0


class Solution:

	def isAmazing(self, n):
		f = 1
		for i in range(2, n + 1):
			if n % i == 0:
				f += 1
				if f > 3:
					return 0
		return 1 if f == 3 else 0


from math import sqrt, floor, ceil

class Solution:

	def isAmazing(self, n):
		ns = sqrt(n)
		if ceil(ns) != floor(ns):
			return 0
		if ns == 2 or ns == 3:
			return 1
		if ns % 2 == 0 or ns == 1:
			return 0
		for i in range(3, int(ns), 2):
			if ns % i == 0:
				return 0
		return 1


class Solution:

	def isAmazing(self, n):
		a = n ** 0.5
		if n ** 0.5 != int(n ** 0.5):
			return 0
		for i in range(2, int(a ** 0.5) + 1):
			if a % i == 0:
				return 0
		return 1


class Solution:

	def isAmazing(self, n):
		if n == 4 or n == 9:
			return 1
		return 0


class Solution:

	def isAmazing(self, n):
		count = 0
		for i in range(2, n):
			if n % i == 0:
				count = count + 1
				if count > 1:
					return 0
		if count == 1:
			return 1
		return 0


import math

class Solution:

	def isAmazing(self, n):

		def isPrime(num):
			if num < 2:
				return 0
			for i in range(2, int(num ** 0.5) + 1):
				if num % i == 0:
					return 0
			return 1
		if isPrime(n) == 1:
			return 0
		t = math.floor(n ** 0.5)
		if t * t == n:
			if isPrime(t) == 1:
				return 1
		return 0


from math import *

class Solution:

	def isAmazing(self, n):
		count = 0
		while n != 0:
			count += 1
			n = n // 2
		if count == 3:
			return 1
		else:
			return 0


import math

class Solution:

	def isAmazing(self, N):
		count = 2
		for itr in range(2, N // 2 + 1):
			if N % itr == 0:
				count += 1
			if count > 3:
				return 0
		if count == 3:
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.isAmazing(n))


class Solution:

	def isAmazing(self, n):
		count = 0
		while n != 0:
			count += 1
			n = n // 2
		if count == 3:
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.isAmazing(n))


class Solution:

	def isAmazing(self, n):
		k = int(n ** 0.5)
		s = {}
		for i in range(1, k + 1):
			if n % i == 0:
				s[i] = 1
				s[n // i] = 1
		if len(s) == 3:
			return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.isAmazing(n))


import math

class Solution:

	def isAmazing(self, n):
		unique_divisors = set()
		i = 1
		while i <= math.sqrt(n):
			if n % i == 0:
				unique_divisors.add(i)
				if n / i != i:
					unique_divisors.add(int(n / i))
			i += 1
		if len(unique_divisors) == 3:
			return 1
		return 0


class Solution:

	def isAmazing(self, n):
		if n < 4:
			return 0
		c = 2
		for i in range(2, n, 1):
			if n % i == 0:
				c += 1
			if c > 3:
				return 0
		if c != 3:
			return 0
		return 1


class Solution:

	def isAmazing(self, n):
		ct = 0
		for x in range(1, int(pow(n, 0.5)) + 1):
			if n % x == 0:
				if x == int(n / x):
					ct += 1
				else:
					ct += 2
		if ct == 3:
			return 1
		return 0


import math

class Solution:

	def isAmazing(self, n):
		if n == 4:
			return 1
		n = int(n ** (1 / 2))
		if n == 1:
			return 0
		for i in range(2, n + 1):
			if n % i == 0:
				return 0
		return 1


import math

def isprime(n):
	if n <= 1:
		return 0
	for i in range(2, int(math.sqrt(n) + 1)):
		if n % i == 0:
			return 0
	return 1

class Solution:

	def isAmazing(self, n):
		sqr = int(math.sqrt(n))
		if sqr * sqr == n:
			if isprime(sqr) == 1:
				return 1
		return 0