Check if a number can be expressed as power | Set 2 ( Using Log ) | javascript program to find if a number can be expressed as x raised to power y . ; Find Log n in different bases and check if the value is an integer ; Driver code
function isPower ( n ) { for ( x = 2 ; x <= parseInt ( Math . sqrt ( n ) ) ; x ++ ) { var f = Math . log ( n ) / Math . log ( x ) ; if ( ( f - parseInt ( f ) ) == 0.0 ) return true ; } return false ; } for ( i = 2 ; i < 100 ; i ++ ) if ( isPower ( i ) ) document . write ( i + " " ) ;