Cod sursa(job #3185893)

Utilizator chiriacandrei25Chiriac Andrei chiriacandrei25 Data 20 decembrie 2023 19:45:49
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>

using namespace std;

const int MOD = 1999999973;

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

int main() {
    int n, p;
    ifstream fin("lgput.in");
    ofstream fout("lgput.out");
    fin >> n >> p;
    fout << logPow(n, p);
    return 0;
}