- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Check whether the given number is Wagstaff prime or not in Python

Suppose we have a number n. We have to check whether n is Wagstaff prime or not. As we know Wagstaff prime is a prime number which is in the following form.

where q is an odd prime number.

So, if the input is like n = 683, then the output will be True n can be represented as

So here q = 11. And q is odd prime.

To solve this, we will follow these steps −

- if num is prime and (num*3 - 1) is also prime, then
- return True

- return False

Let us see the following implementation to get better understanding −

## Example Code

def isPrime(num): if num > 1: for i in range(2, num): if num % i == 0: return False return True return False def power_of_two(num): return num and not(num & (num - 1)) def solve(num) : if isPrime(num) and power_of_two(num * 3-1): return True return False n = 683 print(solve(n))

## Input

683

## Output

True

- Related Questions & Answers
- Check whether the given number is Euclid Number or not in Python
- Check whether N is a Dihedral Prime Number or not in Python
- Check whether the given numbers are Cousin prime or not in Python
- How to check whether a number is prime or not using Python?
- Write a Golang program to check whether a given number is prime number or not
- C++ Program to Check Whether a Number is Prime or Not
- C Program to Check Whether a Number is Prime or not?
- Java Program to Check Whether a Number is Prime or Not
- Program to check whether given number is Narcissistic number or not in Python
- Check whether the sum of prime elements of the array is prime or not in Python
- Program to check whether every rotation of a number is prime or not in Python
- Program to check whether the given number is Buzz Number or not in C++
- Check if a number is Primorial Prime or not in Python
- Check if the given number is Ore number or not in Python
- Python program to check if a number is Prime or not

Advertisements