Suppose we have a number n, we have to check whether n is a primorial prime or not. A number is said to be a primorial prime when it is a prime number of the form pN# + 1 or pN# – 1 , where pN# indicates the primorial of pN such that the product of first N prime numbers.
So, if the input is like 29, then the output will be True as 29 is Primorial prime of the form pN - 1 if N=3, Primorial is 2*3*5 = 30 and 30-1 = 29.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
from math import sqrt MAX = 100000 prime = [True] * MAX arr =  def SieveOfEratosthenes() : for pri in range(2, int(sqrt(MAX)) + 1) : if prime[pri] == True : for i in range(pri * 2 , MAX, pri) : prime[i] = False for pri in range(2, MAX) : if prime[pri] : arr.append(pri) def check_primorial_prime(n) : if not prime[n] : return False product, i = 1, 0 while product < n : product *= arr[i] if product + 1 == n or product - 1 == n : return True i += 1 return False SieveOfEratosthenes() n = 29 print(check_primorial_prime(n))