Highest and Smallest power of K less than and greater than equal to N respectively | Function to return the highest power of k less than or equal to n ; Function to return the smallest power of k greater than or equal to n ; Function to print the result ; Driver code
function prevPowerofK ( n , k ) { var p = parseInt ( Math . log ( n ) / Math . log ( k ) ) ; return parseInt ( Math . pow ( k , p ) ) ; } function nextPowerOfK ( n , k ) { return prevPowerofK ( n , k ) * k ; } function printResult ( n , k ) { document . write ( prevPowerofK ( n , k ) + " " + nextPowerOfK ( n , k ) + " " ) ; } var n = 25 , k = 3 ; printResult ( n , k ) ;