Cod sursa(job #266145)

Utilizator iondionGeorge Pascu iondion Data 24 februarie 2009 22:25:08
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.38 kb
#include <fstream>
#define T 1999999973

using namespace std;

int N, P;

int exp( int N, int P )
{
				if( P==0 ) return 1;
				if( P%2 ) return ( N*exp(N,P-1) )%T;
				else return ( exp(N,P/2)*exp(N,P/2) )%T;
}

int main()
{
				ifstream fin("lgput.in");
				fin >> N >> P;
			  fin.close();

				ofstream fout("lgput.out");
				fout << exp(N,P);
				fout.close();	
				return 0;
}