Cod sursa(job #558229)

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

using namespace std;

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

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