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 whether the sum of prime elements of the array is prime or not
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Check whether a number is circular prime or not
- C Program to Check Whether a Number is Prime or not
- Python program to check whether a number is Prime or not
- Check if a number is a Pythagorean Prime or not
- Check if a number is Quartan Prime or not
- Check whether the given number is Wagstaff prime or not
- Check whether N is a Dihedral Prime Number or not
- Check if all Prime factors of number N are unique or not
- Check if N is a Balanced Prime number or not
- Check whether a number is Good prime or not
- Check if N is a Weak Prime number or not
- Quick ways to check for Prime and find next Prime in Java
- Check whether the sum of absolute difference of adjacent digits is Prime or not
- Check n^2 - m^2 is prime or not
- Check whether the given numbers are Cousin prime or not
- Check whether count of distinct characters in a string is Prime or not
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.