Cod sursa(job #2999072)
Utilizator | Alex Bleotu AlexDavid26 | Data | 10 martie 2023 14:29:10 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
#define lli long long int
using namespace std;
ifstream cin("lgput.in");
ofstream cout("lgput.out");
lli fastPower(lli base, lli power) {
lli powerValue = 1;
while (power) {
if (power % 2 == 1)
powerValue *= base;
base *= base;
power /= 2;
}
return powerValue;
}
int main() {
lli base, power;
cin >> base >> power;
cout << fastPower(base, power);
}