Cod sursa(job #504015)

Utilizator DuxarFII-Stefan-Negrus Duxar Data 26 noiembrie 2010 12:22:40
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include<fstream>
#include<iostream>
#include<algorithm>
#define MDL 1999999973
#define ULL unsigned long long
using namespace std;

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


ULL N,P,Nin;

void read();
ULL powr(ULL P);


int main()
{
	read();
	g<<powr(P);
	f.close();
	g.close();
	return 0;
}

void read()
{
	f>>N>>P;
	N%=MDL;
	Nin=N;
}

ULL powr(ULL P)
{
	unsigned long long x;
	if (P>1)
		if (P%2==0)
		{
			
			x=powr(P/2);
			return (x*x)%MDL;
		}
		else 
		{
			x=powr(P-1);
			return (N*x)%MDL;
		}	
	return N;
}