Given a positive integer N, the task is to check whether the given number is good prime or not. If the given number is good prime print ‘YES’ Otherwise Print ‘NO’.
Good Prime: In Mathematics, a good prime is a prime number whose square is greater than the product of any two primes at the same number of positions before and after it in the sequence of primes. In other word, A prime Pn is said to be good prime if it for every 1 <= i < n.
The first few good primes are: 5, 11, 17, 29, 37, 41, 53, 59, 67, 71, 97, 101, 127, 149, 179, 191, 223, ….
Input: N = 5
Explanation: 5 is a good prime number
since 5^2 = 25 is greater than 3.7 = 21
and 2.11 = 22.
Input: N = 20
1. Get the number N.
2. Initialise prev_prime = N-1 and next_prime = N+1
3. Iterate the loop while prev_prime is greater than or equal to 2. And check for both next_prime and prev_prime are prime of not using prime number.
4. If both are not prime, then repeat step 2 and 3.
5. If both next_prime and prev_prime are prime, then check N^2 > next_prime . prev_prime or not.
- If Not then number is not good prime and stop the execution and return NO.
- If Yes then repeat the step 2, 3, 4 and 5.
Below is the implementaion of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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 if a number is Full Prime
- Check whether N is a Dihedral Prime Number or not
- Check a number for Permutable Prime
- Check if a number is Quartan Prime or not
- Check if a number is a Pythagorean Prime or not
- Check if the first and last digit of number N is prime and their sum is less than K
- Check whether a number is circular prime or not
- C Program to Check Whether a Number is Prime or not
- Check whether the given number is Wagstaff prime or not
- Check if a number is Primorial Prime or not
- Check if N is a Balanced Prime number or not
- Check if N is a Weak Prime number or not
- Check if the number is a Prime power number
- Python program to check whether a number is Prime or not
- Check if a number can be written as a sum of 'k' prime numbers
- Check if all Prime factors of number N are unique or not
- Check if there exists a number with X factors out of which exactly K are prime
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.