Cod sursa(job #558213)

Utilizator Razvan_AlexeRazvan Razvan_Alexe Data 17 martie 2011 09:54:54
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.34 kb
#include <fstream>

using namespace std;

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

int main(){
	int n,rez,px,r,x;
	intrare >> x >> n;
	rez = 1, px = n;
	while (x)
	{
	r = x % 2;
	if (r)
		rez *= px;
	rez = rez % 1999999973;
	px *= px;
	px = px % 1999999973;
	x /= 2;
	}
	iesire << rez << '\n';
	return 0;
}