Cod sursa(job #2999071)

Utilizator AlexDavid26Alex Bleotu AlexDavid26 Data 10 martie 2023 14:27:41
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <fstream>

using namespace std;

ifstream cin("lgput.in");
ofstream cout("lgput.out");

int fastPower(int base, int power) {
    int powerValue = 1;

    while (power) {
        if (power % 2 == 1)
            powerValue *= base;

        base *= base;
        power /= 2;
    }

    return powerValue;
}

int main() {
    int base, power;

    cin >> base >> power;

    cout << fastPower(base, power);
}