Cod sursa(job #3182538)

Utilizator info_manDavid Patrick info_man Data 9 decembrie 2023 09:46:00
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.4 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int main()
{
    long long n, P, res = 0;
    fin >> n >> P;
    while (P)
    {
        if (P & 1)
        {
            res = (res * n) % 1999999973 ;
            n = (n*n) % 1999999973 ;
            P/= 2;
        }
    }
        fout << res << '\n';

    return 0;
}