Cod sursa(job #2237748)

Utilizator kitkat007Graphy kitkat007 Data 2 septembrie 2018 22:37:51
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <fstream>
using namespace std;
#define Int64 long long

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

int powMod(Int64, Int64);

int main() {
	int n, p;
	fin >> n >> p;
	fout << powMod(n, p);
	return 0;
}

int powMod(Int64 base, Int64 exp) {
	const int PRIME = 1999999973;
	if (exp == 0) return 1;
	if (exp & 1) {
		return (base * powMod(base, --exp)) % PRIME;
	}
	else {
		return powMod((base * base) % PRIME, exp >> 1);
	}
}