Cod sursa(job #711662)

Utilizator NicuCJNicu B. NicuCJ Data 12 martie 2012 16:36:19
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.37 kb
#include <fstream>
using namespace std;
int main()
{
	int baza, exp, j, cifre[1000];
	long long p=1;
	ifstream f("lgput.in");
	ofstream g("lgput.out");
	f>>baza>>exp;
	//transformare in baza 2 a exp;
	int x=exp;
	int i=0;
	while(x)
	{
		cifre[i]=x%2;
		i++;
		x=x/2;
	}
	for(j=i-1; j>=0; j--)
	{
		if(cifre[j]==1)
			p=p*p*baza;
		else
			p=p*p;
	}
	g<<p;
}