Cod sursa(job #2253228)

Utilizator hopingsteamMatraguna Mihai-Alexandru hopingsteam Data 3 octombrie 2018 19:47:29
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include    <iostream>
#include   <fstream>

using namespace std;

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

const int MOD = 1999999973;

int RidicareLogaritmica(int N, int P)
{
    int r = 1;
    while(P)
    {
        if(P % 2 == 1)
            r = (1LL * r * N) % MOD;
        N = (1LL * N * N) % MOD;
        P = P / 2;
    }
    return r;
}

int main() {

    int N, P;
    fin >> N >> P;
    fout << RidicareLogaritmica(N, P);
    return 0;
}