Cod sursa(job #1515990)
Utilizator | Data | 2 noiembrie 2015 16:28:48 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int LgPower(int x, int power){
if(power==1){
return x;
}
int k = LgPower(x, power / 2);
k = k * k;
if(power % 2 == 1){
k = k * x;
}
return k;
}
int main()
{
int a,b;
f>>a>>b;
g << LgPower(a, b);
return 0;
}