Cod sursa(job #158773)

Utilizator nimeniaPaul Grigoras nimenia Data 13 martie 2008 20:16:39
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <fstream.h>

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

long long a,ac,b,c=1999999973;

long long putere(long long b){
	long long aux;
	if (b==1) return ac;
	else {
	  if (b%2==1){aux=(putere(b-1)*ac)%c; return aux;}
	  else {aux=putere(b/2); return (aux*aux)%c;}
	}


}


int main()
{	f>>a>>b;
	ac=a%c;
	long long aux;
	aux=putere(b);
	g<<aux;
	f.close();
	g.close();
	return 0;



}