- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 if a number is a Pythagorean Prime or not in C++
Here we will see another program to check whether a number is Pythagorean Prime or not. Before dive into the logic, let us see what are the Pythagorean Prime numbers? The Pythagorean primes are prime numbers, that can be represented as 4n + 1.
To detect a number is like that, we have to check whether the number is prime or not, if it is prime, then we will divide the number by 4, and if the remainder is 1, then that is Pythagorean prime number. Some Pythagorean prime numbers are {5, 13, 17, 29, 37, 41, 53, …}
Example
#include <iostream> using namespace std; bool isPrime(int n){ for(int i = 2; i<= n/2; i++){ if(n % i == 0){ return false; } } return true; } bool isPythagoreanPrime(int n) { if(isPrime(n) && ((n % 4) == 1)){ return true; } return false; } int main() { int num = 29; if(isPythagoreanPrime(num)){ cout << "The number is Pythagorean Prime"; }else{ cout << "The number is not Pythagorean Prime"; } }
Output
The number is Pythagorean Prime
- Related Articles
- Check if a number is Quartan Prime or not in C++
- Check if a number is Primorial Prime or not in C++
- C# Program to check if a number is prime or not
- Write a C# program to check if a number is prime or not
- Check if a number is Primorial Prime or not in Python
- Python program to check if a number is Prime or not
- PHP program to check if a number is prime or not
- Bash program to check if the Number is a Prime or not
- C++ Program to Check Whether a Number is Prime or Not
- C Program to Check Whether a Number is Prime or not?
- Check if a number is a Krishnamurthy Number or not in C++
- How to check whether a number is a prime number or not?
- Check if a number is jumbled or not in C++
- Check if a number is an Unusual Number or not in C++
- Check if a number is an Achilles number or not in C++

Advertisements