Compute power of power k times % m | Function to compute the given value ; compute power k times ; Driver Code ; Calling function
function calculate ( x , k , m ) { let result = x ; k = k - 1 ; while ( k -- ) { result = Math . pow ( result , x ) ; if ( result > m ) result %= m ; } return result ; } let x = 5 ; let k = 2 ; let m = 3 ; document . write ( calculate ( x , k , m ) ) ;