Check if a number can be expressed as a ^ b | Set 2 | Javascript program to check if a number can be expressed as a ^ b . ; Driver code
function isPower ( a ) { if ( a == 1 ) return true ; for ( let i = 2 ; i * i <= a ; i ++ ) { let val = Math . log ( a ) / Math . log ( i ) ; if ( ( val - Math . floor ( val ) ) < 0.00000001 ) return true ; } return false ; } let n = 16 ; document . write ( isPower ( n ) ? " " : " " ) ;