Logarithm tricks for Competitive Programming | C ++ implementation to check that a integer is a power of Two ; Function to check if the number is a power of two ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPowerOfTwo ( int n ) { return ( ceil ( log2 ( n ) ) == floor ( log2 ( n ) ) ) ; } int main ( ) { int N = 8 ; if ( isPowerOfTwo ( N ) ) { cout << " Yes " ; } else { cout << " No " ; } }