Cod sursa(job #2569353)

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