Cod sursa(job #2752732)

Utilizator george_buzasGeorge Buzas george_buzas Data 19 mai 2021 12:08:31
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.55 kb
#include <fstream>
#define mod 1999999973
using namespace std;

long long compute_power(long long base, long long exponent) {
	if (base == 0) {
		return 0;
	}
	if (exponent == 0) {
		return 1;
	}
	if (exponent % 2) {
		return ((base % mod) * (compute_power(base % mod, exponent - 1) % mod)) % mod;
	}
	if (!(exponent % 2)) {
		return (compute_power((base * base) % mod, exponent / 2)) % mod;
	}
}

int main() {
	ifstream fin("lgput.in");
	ofstream fout("lgput.out");
	long long n, p;
	fin >> n >> p;
	fout << compute_power(n, p);
	return 0;
}