Cod sursa(job #558164)

Utilizator VladLupoaieVlad Lupoaie VladLupoaie Data 17 martie 2011 09:35:22
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.33 kb
#include <fstream>

using namespace std;

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

long long int rez=1,p,n,px,rest;

int main ()
{
	fin>>n>>p;
	px=n;
	while (p)
	{
		rest=p%2;
		if (rest) rez*=px;
		rez=rez%1999999973;
		px*=px;
		px=px%1999999973;
		p=p/2;
	}
	fout<<rez;
	return 0;
	fout.close();
}