Cod sursa(job #2816551)

Utilizator walentines44Serban Valentin walentines44 Data 11 decembrie 2021 15:35:38
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.47 kb
#include <fstream>

using namespace std;

long long exp(long long x, long long y){
    if(y == 1){
        return x % 1999999973;
    }
    if(y % 2 == 0){
        return exp(x * x % 1999999973, y / 2) % 1999999973;
    }
    else{
        return exp(x * x % 1999999973, y / 2) * x % 1999999973;
    }
}

int main(){
    ifstream fin("lgput.in");
    ofstream fout("lgput.out");
    long long N, P;
    fin >> N >> P;
    long long ans = exp(N, P);
    fout << ans;

    return 0;
}