Cod sursa(job #3357804)

Utilizator TestLicenta123Test Test TestLicenta123 Data 13 iunie 2026 15:06:26
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
#include <iostream>
#include <fstream>

#define PRIME 1999999973

typedef unsigned long long u64;

u64 pow(u64 base, u64 exponent) {
    u64 ans = 1;
    base %= PRIME;
    while (exponent > 0) {
        if (exponent & 1) ans = (ans * base) % PRIME;
        exponent >>= 1;
        base = (base * base) % PRIME;
    }
    return ans;
}

int main() {
    std::ifstream input("lgput.in");
    std::ofstream output("lgput.out");

    u64 n, p;
    input >> n >> p;
    output << pow(n, p);

    return 0;
}