Cod sursa(job #2324875)

Utilizator mihnea.tTudor Mihnea mihnea.t Data 21 ianuarie 2019 17:36:56
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.41 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n, p;
long long s = 1, x;

const long long mx = 1999999973;

int main()
{
    fin>>n>>p;

    int i = 0;

    x = n;

    while (p)
    {
        if (p % 2 == 1) s = (s * x) % mx;

        p >>= 1;
        x = (x * x) % mx;
    }

    fout<<s;

    return 0;
}