Returns true if n can be written as x ^ y
static bool isPower ( int n ) { double p ; if ( n <= 1 ) { return true ; } for ( int i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) { p = Math . Log ( n ) / Math . Log ( i ) ; if ( ( Math . Ceiling ( p ) == Math . Floor ( p ) ) && p > 1 ) { return true ; } } return false ; }