
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Check if a number is Quartan Prime or not in C++
Here we will see another program to check whether a number is Quartan Prime or not. Before dive into the logic, let us see what are the Quartan Prime numbers? The Quartan primes are prime numbers, that can be represented as x4 + y4. The x, y > 0.
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 16, and if the remainder is 1, then that is Quartan prime number. Some Quartan prime numbers are {2, 17, 97, …}
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 isQuartanPrime(int n) { if(isPrime(n) && ((n % 16) == 1)){ return true; } return false; } int main() { int num = 97; if(isQuartanPrime(num)){ cout << "The number is Quartan Prime"; }else{ cout << "The number is not Quartan Prime"; } }
Output
The number is Quartan Prime
- Related Articles
- Check if a number is Primorial Prime or not in Python
- Check if a number is Primorial Prime or not in C++
- Check if a number is a Pythagorean Prime or not in C++
- C# Program to check if a number is prime or not
- 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
- Write a C# program to check if a number is prime or not
- How to check whether a number is a 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
- Check whether N is a Dihedral Prime Number or not in Python
- Check if LCM of array elements is divisible by a prime number or not in Python
- How To Check Whether a Number is Pointer Prime Number or Not in Java?

Advertisements