Cod sursa(job #2214746)

Utilizator dia.ionescuIonescu Diana dia.ionescu Data 19 iunie 2018 23:30:25
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
#include <iostream>
#include <fstream>

using namespace std;

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

#define NR 1999999973;

int main()
{
    int N, P;
    long long x, y = 1;
    fin >> N >> P;
    x = N;
    while (P) {
        if (P % 2) {
            y = y * x;
            P--;
        }
        x = x * x;
        P = P / 2;
    }
    fout << y % NR;
}