Check if a number can be expressed as x ^ y ( x raised to power y ) | Returns true if n can be written as x ^ y ; Driver code
function isPower ( n ) { let p ; if ( n <= 1 ) { return true ; } for ( let i = 2 ; i <= parseInt ( Math . sqrt ( n ) , 10 ) ; i ++ ) { p = ( Math . log ( n ) / Math . log ( i ) ) . toFixed ( 14 ) ; if ( ( Math . ceil ( p ) == Math . floor ( p ) ) && ( p > 1 ) ) { return true ; } } return false ; } for ( let i = 2 ; i < 100 ; i ++ ) { if ( isPower ( i ) ) document . write ( i + " " ) ; }