Cod sursa(job #558197)

Utilizator Razvan_AlexeRazvan Razvan_Alexe Data 17 martie 2011 09:46:34
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.36 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 = x;
	while (n)
	{
	r = n % 2;
	if (r)
	rez = (rez % 1999999973 * px % 1999999973) % 1999999973;
	px = (px * px) % 1999999973;
	n /= 2;
	}
	iesire << rez << '\n';
	return 0;
}