Cod sursa(job #2619180)

Utilizator vladtomaVlad Toma Grosu vladtoma Data 27 mai 2020 11:16:14
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.39 kb
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
ifstream in ("lgput.in");
ofstream out ("lgput.out");
#define MOD 1999999973
int main()
{
    unsigned long long n, p=1, P;
    in >> n >> P;
    while (P)
    {
        if (P%2==1)
        p=(p%MOD)*(n%MOD);
        n=(n%MOD)*(n%MOD);
        P=(P%MOD)/2;
    }
    out << p%MOD;
    return 0;
}