Cod sursa(job #2736650)

Utilizator niculaandreiNicula Andrei Bogdan niculaandrei Data 3 aprilie 2021 18:45:37
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <bits/stdc++.h>

using namespace std;

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

const int MOD = 1999999973;

int N, P;

int LogPow(int n, int p)
{
    if (p == 0) {
        return 1;
    }
    else if (p % 2 == 0) {
        return LogPow(1LL * n * n % MOD, p / 2);
    }
    else {
        return 1LL * n * LogPow(1LL * n * n % MOD, p / 2) % MOD;
    }
}

int main()
{
    fin >> N >> P;
    fout << LogPow(N, P) << "\n";
    return 0;
}