Returns true if n can be written as x ^ y
static boolean 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 . ceil ( p ) == Math . floor ( p ) ) && p > 1 ) { return true ; } } return false ; }