Cod sursa(job #2379350)

Utilizator nicolaee2Martinescu Nicolae nicolaee2 Data 13 martie 2019 13:40:51
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 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;
}

void Read()
{
    int N, P;
    fin >> N >> P;
    fout << RidicareLogaritmica(N, P);
}

int main()
{
    Read();
    return 0;
}