Cod sursa(job #930806)

Utilizator mottyMatei-Dan Epure motty Data 27 martie 2013 20:23:57
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>

using namespace std;

const int MOD =  1999999973;

ifstream in("lgput.in");
ofstream out("lgput.out");

long long power(int base, int exp) {
	if (exp == 1)
		return base % MOD;
	if (exp % 2 == 0)
		return (power(base*base, exp/2)) % MOD;
	return (base * power(base*base, exp/2)) % MOD;
}

int main() {
	long long n, p;
	in >> n >> p;

	out << power(n, p) << "\n";

	return 0;
}