Cod sursa(job #2930332)

Utilizator SkaduweePavel Bogdan Stefan Skaduwee Data 28 octombrie 2022 08:16:20
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <fstream>

using namespace std;

int main()
{
    ifstream fin("lgput.in");
    ofstream fout("lgput.out");
    unsigned long long a, b, aux = 1, rez = 1, putere, aux3;
    fin >> a >> b;
    putere = a;
    while (aux<=b)
    {
        aux3 = (b & aux);
        if (aux3 != 0)
            rez*=putere;
        rez %= 1999999973;
        aux <<= 1;
        putere*= putere;
        putere %= 1999999973;
    }
    fout << rez%1999999973;
    return 0;
}