Suppose we have a number n. We have to check whether n is Euclid number or not. As we know Euclid numbers are integer which can be represented as
where is product of first n prime numbers.
So, if the input is like n = 211, then the output will be True n can be represented as
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
MAX = 10000 primes =  def generate_all_primes(): prime = [True] * MAX x = 2 while x * x < MAX : if prime[x] == True: for i in range(x * 2, MAX, x): prime[i] = False x += 1 for x in range(2, MAX): if prime[x]: primes.append(x) def solve(n): generate_all_primes() mul = 1 i = 0 while mul < n : mul = mul * primes[i] if mul + 1 == n: return True i += 1 return False n = 211 print(solve(n))