Cod sursa(job #2175736)

Utilizator AlexnolifeAlexandru Ica Alexnolife Data 16 martie 2018 18:44:15
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>

std::ifstream f("lgput.in");
std::ofstream g("lgput.out");

constexpr int mod = 1999999973;

using uint64 = unsigned long long;

uint64 x, y;

uint64 Pow(uint64 x, uint64 y)
{
	if (x == 1)
		return 1;
	else if (x == 0)
		return 0;
	else if (y == 1)
		return x;
	else if (y % 2 == 1) {
		uint64 aux = Pow(x, (y / 2));
		return (((aux * aux) % mod) * x) % mod;
	}
	else {
		uint64 aux = Pow(x, (y / 2));
		return (aux * aux) % mod;
	}
}

int main(int argc, char * argv[])
{
	f >> x >> y;

	g << Pow(x, y);

	return 0;
}