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 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 whether N is a Dihedral Prime Number or not
- C Program to Check Whether a Number is Prime or not
- 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 if a number is Primorial Prime or not
- Check a number for Permutable Prime
- Check if a number is Full Prime
- 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 LCM of array elements is divisible by a prime number or not
- Check if there exists a prime number which gives Y after being repeatedly subtracted from X
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.