Modular Exponentiation

PHOTO EMBED

Tue Oct 12 2021 02:15:38 GMT+0000 (UTC)

Saved by @code_ea

#include <iostream>
#include <limits.h>
using namespace std;

 int power(int x, int n)
{
	if(n == 0)
		return 1;

	int temp = power(x, n/2);

	temp = temp * temp;

	if(n % 2 == 0)
		return temp;
	else
		return temp * x; 
}
int main() {
    
    int x = 3, n = 5;

	cout<<power(x, n);
}
content_copyCOPY

https://ide.geeksforgeeks.org/vhLhbMRd9d