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 whether the sum of prime elements of the array is prime or not
- Check whether the given numbers are Cousin prime or not
- Check whether all the rotations of a given number is greater than or equal to the given number or not
- 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 whether N is a Dihedral Prime Number or not
- Check whether a number is Good prime or not
- Check whether the sum of absolute difference of adjacent digits is Prime or not
- Check whether count of distinct characters in a string is Prime or not
- Check whether the frequencies of all the characters in a string are prime or not
- Check whether the given number is Euclid Number or not
- Check whether given number N is a Moran Number or not
- Check whether a given number N is a Nude Number or not
- Check whether a given number is an ugly number or not
- Check whether a given number is Polydivisible or Not
- Check whether a given Number is Power-Isolated or not
- Check whether a number has consecutive 0's in the given base or not
- Check whether the binary equivalent of a number ends with given string or not
- Check Whether a number is Duck Number 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.