Given a positive integer n. Find whether a number is a semiprime or not.
 Note: A semiprime is a natural number that is a product of two prime numbers .
Example 1:
Input:
N=35
Output:
1
Explanation:
35=7x5.So 35 is a semi-prime.
Example 2:
Input:
8
Output:
0
Explanation:
8 is not a semi prime.
Your Task:
You don't need to read input or print anything.Your Task is to complete the function checkSemiprime() which takes a number N as input parameter and returns 1 if it is a semi prime number.Otherwise, it returns 0.
Expected Time Complexity:O(Sqrt(N))
Expected Auxillary Space:O(1)
Constraints:
1<=N<=10^{9}

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Starter code: #User function Template for python3

class Solution:
    def checkSemiprime(self,N):
        #code here

Solutions:
import math

class Solution:

	def checkSemiprime(self, n):

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

		def isprime(n):
			for i in range(1, int(math.sqrt(n)) + 1):
				if n % i == 0:
					if prime(i) == 0 and prime(n // i) == 0:
						return 1
			return 0
		x = isprime(n)
		if x == 0:
			return 0
		return 1


from math import sqrt

class Solution:

	def checkSemiprime(self, n):
		count = 0
		i = 2
		while i * i <= n and count < 2:
			while n % i == 0:
				n /= i
				count += 1
			i += 1
		if n > 1:
			count += 1
		if count == 2:
			return 1
		return 0


class Solution:

	def checkSemiprime(self, N):
		k = int(N ** 0.5)
		s = {}
		c = 0
		for i in range(2, k + 1):
			while N % i == 0:
				c += 1
				N = N // i
			if c > 2:
				return 0
		if N != 1:
			c += 1
		if c == 2:
			return 1
		return 0


class Solution:

	def checkSemiprime(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

		def spf(num):
			k = 2
			while k * k < num:
				if num % k == 0:
					return k
				k += 1
			return num
		x = spf(N)
		if isPrime(N // x) == 1:
			return 1
		return 0


class Solution:

	def checkSemiprime(self, N):
		c = 0
		while N % 2 == 0:
			N = N // 2
			c += 1
		i = 3
		while i * i <= N:
			while N % i == 0:
				c += 1
				N = N // i
			i += 2
		if N > 2:
			c += 1
		if c == 2:
			return 1
		else:
			return 0


class Solution:

	def checkSemiprime(self, N):
		import math
		num = N
		cnt = 0
		for i in range(2, int(math.sqrt(num)) + 1):
			while num % i == 0:
				num /= i
				cnt += 1
			if cnt >= 2:
				break
		if num > 1:
			cnt = cnt + 1
		if cnt == 2:
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.checkSemiprime(N))