Given a positive integer n, the task is to check if it is a Wagstaff prime or not. Print ‘YES’ if the given number is Wagstaff prime otherwise print ‘NO’.
Wagstaff prime: In mathematics, Wagstaff prime is a prime number ‘n’ of the form
where ‘q’ is an odd prime.
First few Wagstaff prime numbers are:
3, 11, 43, 683, 2731, 43691, 174763, 2796203……….
Input: 43 Output: Yes 43 can be expressed as - (27 + 1 )/ 3 Input: 31 Output: No 31 can not be expressed in above mentioned form.
- Check first if the given number is prime number or not. To check for a number to be prime, refer this.
- Then check if it can be expressed in the form of (n * 3 – 1) and should be a power of 2. To check for a number to be power of 2, refer this.
- If both conditions are true, then the number is a Wagstaff prime number. Hence print “YES”. Otherwise print “NO”
Below is the implementation of above approach:
- 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 the first and last digit of number N is prime and their sum is less than K
- C Program to Check Whether a Number is Prime or not
- Check if a number is Full Prime
- Check if a number is a Pythagorean Prime or not
- Check if a number is Quartan Prime or not
- Check whether a number is circular prime or not
- Check if a number is Primorial Prime or not
- Check a number for Permutable Prime
- Check whether N is a Dihedral Prime Number or not
- Check if a number can be written as a sum of 'k' prime numbers
- Python program to check whether a number is Prime or not
- Check if all Prime factors of number N are unique 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 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.