Program to check whether a number is Proth number or not in C++

C++Server Side ProgrammingProgramming

Given with a number ‘n’ and the task is to determine whether the given positive integer is a proth or not and display the result as an output.

What is Proth Number?

A proth number is given by


Where, n is a positive integer and k is a odd positive integer

The first few proth numbers are given below −

3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97.......


number: 17


its a proth number


number: 18


its not a proth number

Approach used in the given program is as follows

  • Input the number to check for the condition

  • Apply the given formula to check whether its a proth number or not

  • If the condition holds true print its a proth number

  • If the condition doesn’t holds true print its not a proth number


Step 1→ declare function to calculate power of 2
   bool isPower(int num)
      return (num && !(num & (num - 1)))
Step 2→ Declare function to check if a number is a proth number or not
   bool isProth(int num)
      declare int k = 1
      While (k < (num / k))
         IF (num % k == 0)
            IF (isPower(num / k))
               return true
            Set k = k + 2
      return false
Step 3→ In main()
   Declare int num = 17
   IF (isProth(num - 1))
      Print "its a proth number"
      Print "its not a proth number"


 Live Demo

#include <bits/stdc++.h>
using namespace std;
//function to calculate power of 2
bool isPower(int num){
   return (num && !(num & (num - 1)));
//function to check if a number is a proth number
bool isProth(int num){
   int k = 1;
   while (k < (num / k)){
      if (num % k == 0){
         if (isPower(num / k))
            return true;
      k = k + 2;
   return false;
int main(){
   int num = 17;
   if (isProth(num - 1))
      cout << "its a proth number";
      cout << "its not a proth number";
   return 0;


If run the above code it will generate the following output −

its a proth number
Published on 13-Aug-2020 10:35:19