Cod sursa(job #504008)

Utilizator DuxarFII-Stefan-Negrus Duxar Data 26 noiembrie 2010 12:03:06
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include<fstream>
#include<iostream>
#include<algorithm>
#define MDL 1999999973
using namespace std;

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

char v[2001],v2[2001];
int pw[2001];
unsigned long long N,P,Nin;

void read();
void powr();


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

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

void powr()
{
	if (P%2==0&&P)
	{
		N*=N;
		P/=2;
		powr();
	}
		else if (P>1)
	{
		N*=Nin;
		N%=MDL;
		P/=2;
		powr();
	}	
}