A Sphenic Number is a positive integer N which is product of exactly three distinct primes. The first few sphenic numbers are 30, 42, 66, 70, 78, 102, 105, 110, 114, …
Given a number N, your task is to find whether it is a Sphenic Number or not.
 
Example 1:
Input: N = 30
Output: 1
Explanation: 30 = 2 * 3 * 5 so N is 
product of 3 distinct prime numbers.
Example 2:
Input: N = 60
Output: 0
Explanation: 60 = 2 * 2 * 3 * 5 so N is
product of 4 prime numbers.
 
Your Task:
You don't need to read or print anyhting. Your task is to complete the function isSphenicNo() which takes N as input parameter and returns 1 if N is Sphenic Number otherwise returns 0.
 
Expected Time Complexity: O(N* log(N))
Expected Space Complexity: O(N)
 
Constraints:
1 <= N <= 1000

Difficulty: EASY
Tags: Number theory
Expected Time Complexity: O(N* log(N))
Expected Auxiliary Space: O(N)

Starter code:
#User function Template for python3

class Solution:
	def isSphenicNo(self, N):
		# Code here

Solutions:
def ISprime(n):
	for i in range(2, n):
		if n % i == 0:
			return 0
	return 1

class Solution:

	def isSphenicNo(self, N):
		l = []
		for i in range(2, N):
			if N % i == 0 and ISprime(i):
				l.append(i)
		if len(l) < 3:
			return 0
		if len(l) >= 3:
			for i in range(0, len(l) - 2):
				if N % l[i] == 0:
					if l[i] * l[i + 1] * l[i + 2] == N:
						return 1
					else:
						continue
				else:
					continue
		return 0


class Solution:

	def isSphenicNo(self, N):
		p = [2]
		for i in range(3, N + 1):
			for k in range(2, i):
				if i % k == 0:
					break
				if k == i - 1:
					p.append(i)
		j = []
		for m in range(len(p)):
			if N % p[m] == 0:
				N = N / p[m]
				j.append(p[m])
		if len(j) == 3 and N == 1:
			return 1
		else:
			return 0


class Solution:

	def isSphenicNo(self, N):

		def isprime(n):
			if n == 1:
				return False
			for i in range(2, int(n ** 0.5) + 1):
				if n % i == 0:
					return False
			return True
		current = 1
		count = 0
		for i in range(1, N + 1):
			if N % i == 0 and isprime(i):
				count += 1
				current *= i
				if count > 3 and current > N:
					return 0
		if count == 3 and current == N:
			return 1
		return 0


class Solution:

	def isSphenicNo(self, N):

		def pf(n):
			i = 2
			res = []
			while i * i <= n:
				if n % i == 0:
					res.append(i)
					while n % i == 0:
						n = n // i
				i += 1
			if n != 1:
				res.append(n)
			return res
		res = pf(N)
		if len(res) != 3:
			return 0
		ans = res[0] * res[1] * res[2]
		if ans == N:
			return 1
		return 0


class Solution:

	def isSphenicNo(self, N):
		spf = [0] * (N + 1)
		for i in range(2, N + 1):
			spf[i] = i
		for i in range(2, int(N ** 0.5) + 1):
			if spf[i] == i:
				for j in range(i * i, N + 1, i):
					if spf[j] == j:
						spf[j] = i
		cnt = 0
		while N > 1:
			x = spf[N]
			cnt += 1
			ans = 0
			while N % x == 0:
				ans += 1
				N = N // x
			if ans > 1:
				return 0
		if cnt == 3:
			return 1
		return 0


import math

class Solution:

	def isprime(self, n):
		if n <= 1:
			return False
		i = 2
		while i <= int(math.sqrt(n)):
			if n % i == 0:
				return False
			i += 1
		return True

	def isSphenicNo(self, N):
		count = 0
		mul = 1
		i = 2
		while i <= N:
			if N % i == 0:
				if self.isprime(i):
					count += 1
					mul = mul * i
			i += 1
		if count == 3 and mul == N:
			return 1
		else:
			return 0


import math

class Solution:

	def isSphenicNo(self, N):
		if N == 0:
			return 0
		sph = 0
		s = 0
		while N % 2 == 0:
			s += 1
			N = N / 2
		if s > 1:
			return 0
		if s == 1:
			sph += 1
		for i in range(3, int(math.sqrt(N)) + 1, 2):
			s = 0
			while N % i == 0:
				N = N / i
				s += 1
			if s > 1:
				return 0
			if s == 1:
				sph += 1
		if N > 2:
			sph += 1
		if sph == 3:
			return 1
		else:
			return 0


class Solution:

	def is_prime(self, x):
		for j in range(2, int(x ** (1 / 2)) + 1):
			if x % j == 0:
				return False
		return True

	def isSphenicNo(self, N):
		c = 0
		s = 2
		d = 0
		while N > 1:
			if self.is_prime(s) and N % s == 0:
				d += 1
				while N % s == 0:
					N = N // s
					c += 1
			s += 1
		if c == 3 and d == 3:
			return 1
		else:
			return 0


class Solution:

	def isSphenicNo(self, N):
		c = []
		a = 2
		while N > 1:
			if N % a == 0:
				N = N // a
				if a in c:
					return 0
				c.append(a)
				if len(c) > 3:
					return 0
			else:
				a = a + 1
		if len(c) == 3:
			return 1
		return 0