Utility function to check if number is a perfect power or not
function isPower ( $ a ) { if ( $ a == 1 ) return true ; for ( $ i = 2 ; $ i * $ i <= $ a ; $ i ++ ) { $ val = log ( $ a ) / log ( $ i ) ; if ( ( $ val - ( int ) $ val ) < 0.00000001 ) return true ; } return false ; }