Thabit number | CPP program to check if a given number is Thabit number or not . ; Utility function to check power of two ; function to check if the given number is Thabit Number ; Add 1 to the number ; Divide the number by 3 ; Check if the given number is power of 2 ; Driver Program ; Check if number is thabit number
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPowerOfTwo ( int n ) { return ( n && ! ( n & ( n - 1 ) ) ) ; } bool isThabitNumber ( int n ) { n = n + 1 ; if ( n % 3 == 0 ) n = n / 3 ; else return false ; if ( isPowerOfTwo ( n ) ) return true ; else return false ; } int main ( ) { int n = 47 ; if ( isThabitNumber ( n ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }