Given a positive number N, the task is to check if N is a primorial prime number or not. Print ‘YES’ if N is a primorial prime number otherwise print ‘NO.
Primorial Prime: In Mathematics, A Primorial prime is a prime number of the form pn# + 1 or pn# – 1 , where pn# is the primorial of pn i.e the product of first n prime numbers.
Input : N = 5 Output : YES 5 is Primorial prime of the form pn - 1 for n=2, Primorial is 2*3 = 6 and 6-1 =5. Input : N = 31 Output : YES 31 is Primorial prime of the form pn + 1 for n=3, Primorial is 2*3*5 = 30 and 30+1 = 31.
The First few Primorial primes are:
2, 3, 5, 7, 29, 31, 211, 2309, 2311, 30029
- Generate all prime number in the range using Sieve of Eratosthenes.
- Check if n is prime or not, If n is not prime Then print No
- Else, starting from first prime (i.e 2 ) start multiplying next prime number and keep checking if product + 1 = n or product – 1 = n or not
- If either product+1=n or product-1=n, then n is a Primorial Prime Otherwise not.
Below is the implementation of above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Primorial of a number
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check if a number is divisible by all prime divisors of another number
- Check whether a number is circular prime or not
- Check if the first and last digit of number N is prime and their sum is less than K
- Check if N is a Weak Prime number or not
- Check whether a number is Good prime or not
- Check if N is a Balanced Prime number or not
- Check whether the given number is Wagstaff prime or not
- Check if a number is Quartan Prime or not
- Check whether N is a Dihedral Prime Number or not
- Check if a number is a Pythagorean Prime or not
- C Program to Check Whether a Number is Prime or not
- Check a number for Permutable Prime
- Check if a number is Full Prime
- Check if the number is a Prime power number
- Check if there exists a number with X factors out of which exactly K are prime
- Python program to check whether a number is Prime or not
- Check if A can be converted to B by reducing with a Prime number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.