Cod sursa(job #2468167)

Utilizator PalcPalcu Stefan Palc Data 5 octombrie 2019 13:15:12
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>
using namespace std;

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

int P(int a, int n)
{
    int rez = 1;
    while (n > 0)
    {
        if (n % 2 == 1)
            rez = 1LL * rez * a % 1999999973;
        n = n / 2;
        a =  1LL * a * a % 1999999973;
    }
    return rez;
}

int main()
{
    int n, p;
    fin >> n >> p;
    fout << P(n, p);
    return 0;
}