Cod sursa(job #1171594)

Utilizator hasmasandragosHasmasan Dragos hasmasandragos Data 15 aprilie 2014 22:49:21
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
#include <fstream>
using namespace std;

ifstream f("lgput.in");
ofstream g("lgput.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);
 f.close();
 g.close();
    return 0;
}