Compute power of power k times % m | C ++ program for computing x ^ x ^ x ^ x . . % m ; Function to compute the given value ; compute power k times ; Driver Code ; Calling function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calculate ( int x , int k , int m ) { int result = x ; k -- ; while ( k -- ) { result = pow ( result , x ) ; if ( result > m ) result %= m ; } return result ; } int main ( ) { int x = 5 , k = 2 , m = 3 ; cout << calculate ( x , k , m ) ; return 0 ; }