Cod sursa(job #2561545)
Utilizator | Data | 28 februarie 2020 21:59:32 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
int pow(int b, int e) {
if ( e == 1)
return b;
if( e % 2 == 1) {
return b * pow(b * b, e / 2);
}
return pow(b * b, e / 2);
}
int main(void) {
ifstream in;
ofstream out;
in.open ("lgput.in");
out.open ("lgput.out");
in.is_open();
int a, b;
in>>a>>b;
out<<pow(a,b)<<"\n";
in.close();
out.close();
return 0;
}