Cod sursa(job #2399341)
Utilizator | Stoica Marius-Andrei stoicaandrei | Data | 7 aprilie 2019 13:29:32 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.31 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int power(int a, int b)
{
if (b == 0)
return 1;
int c = power(a, b / 2);
if (b % 2 == 0)
return c * c;
else
return c * c * a;
}
int main() {
int a, b;
fin >> a >> b;
fout << power(a, b);
}