Cod sursa(job #3301071)
| Utilizator | Data | 21 iunie 2025 14:37:15 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
using namespace std;
ifstream cin("lgput.in");
ofstream cout("lgput.out");
long long lgput(long long base, long long exp) {
if (exp == 0) return 1;
long long half = lgput(base, exp / 2);
if (exp % 2 == 0) {
return half * half;
} else {
return base * half * half;
}
}
int main() {
int a, b; cin >> a >> b;
cout << lgput(a, b);
return 0;
}
