
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 If a Number is Quartan Prime 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
Advertisements