Cod sursa(job #1382102)

Utilizator gabi.cristacheGabi Cristache gabi.cristache Data 8 martie 2015 14:04:44
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <iostream>
#include <fstream>

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

int main() {
	const int k = 1999999973;
	long long result = 1, currentPower;
	unsigned int n, p;
	fin >> n >> p;

	currentPower = n;

	for (int i = 0; (1 << i) <= p; ++i) {
		if (((1 << i) & p) > 0)
			result = (result * currentPower) % k;
		currentPower = (currentPower * currentPower) % k;
	}

	fout << result << '\n';

	return 0;
}