Cod sursa(job #664258)

Utilizator zeeboBuzatu Vlad zeebo Data 19 ianuarie 2012 20:55:49
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.37 kb
#include <fstream>
#define M 1999999973 
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int a,b,n,put,p;
int pow (int a, int b)
{
	int aux;
	if (b==0) return 1;
	else
	if (b%2==0)
	{
		aux=pow(a,b/2);
		return (aux*aux)%M;
	}
	else return (a*pow(a,b-1))%M;
}
int main ()
{
	f>>n>>p;
	put=pow(n,p);
	g<<put%M<<'\n';
return 0;
}