Cod sursa(job #2738937)

Utilizator andreiiorgulescuandrei iorgulescu andreiiorgulescu Data 6 aprilie 2021 16:16:14
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.36 kb
#include <bits/stdc++.h>

using namespace std;

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

int main()
{
    long long fin = 1,n,p;
    in >> n >> p;
    while (p != 0)
    {
        if (p % 2 == 1)
            fin *= n;
        n *= n;
        p = p / 2;
        n = n % 1999999973;
    }
    out << fin % 1999999973;
    return 0;
}