Cod sursa(job #2569370)

Utilizator alexboldasAlex Boldas alexboldas Data 4 martie 2020 11:56:35
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.39 kb
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long Putere(long long A, long long n) {
    long long P = 1;
    while (n)
    {
        if (n % 2 == 1)
            P = P * A;
        A = A * A;
        n /= 2;
    }
    return P;
}
int main() {
    long long a, b;
    fin >> a >> b;
    fout << Putere(a, b);
    return 0;
}