Cod sursa(job #1171592)
Utilizator | Data | 15 aprilie 2014 22:47:13 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
using namespace std;
ifstream f("logput.in");
ofstream g("logput.out");
int b,e;
int putere(int baza,int expo)
{
if (!expo)
return 1;
if (expo%2==0)
return putere(baza,expo/2)*putere(baza,expo/2);
else
return putere(baza,expo/2)*putere(baza,expo/2)*baza;
}
int main()
{f>>b>>e;
g<<putere(b,e);
return 0;
}