Cod sursa(job #2320663)

Utilizator andra_moldovanAndra Moldovan andra_moldovan Data 14 ianuarie 2019 23:33:24
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.5 kb
#include <fstream>

using namespace std;

ifstream fin("lgput.in");
ofstream fout("lgput.out");

inline void Read(int &baza, int &exp) {
    fin >> baza >> exp;
}

inline long long Solve(int baza, int exp) {
    long long sol = 1;
    while (exp) {
        if (exp & 1) {
            sol *= baza;
            exp--;
        }
        exp >>= 1;
        baza *= baza;
    }
    return sol;
}

int main () {
    int baza, exp;
    Read(baza, exp);

    fout << Solve(baza, exp);
}