Returns true if n can be written as x ^ y
bool isPower ( unsigned n ) { float p ; if ( n <= 1 ) return 1 ; for ( int i = 2 ; i <= sqrt ( n ) ; i ++ ) { p = log2 ( n ) / log2 ( i ) ; if ( ( ceil ( p ) == floor ( p ) ) && p > 1 ) return true ; } return false ; }