Cod sursa(job #2381481)

Utilizator ShumaherAdasga Shumaher Data 16 martie 2019 20:45:27
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");


long long int lgput(long long int A, long long int  B, long long int C) {
    long long int y = 1;
    if(B == 0 || A == 1)
        return 1;
    while(B > 1)
        if(B % 2 == 0) {
            B = B / 2;
            A = A * A % C;

        } else {
            B = (B - 1) / 2;
            y = y * A % C;
            A = A * A % C;
        }

    return A * y % C;
}
int main() {long long int  A,B;
    in >> A >> B;
    out<<lgput(A,B,1999999973);
    return 0;
}