Cod sursa(job #3357583)

Utilizator gglvxxGlavan Andrei Gabriel gglvxx Data 11 iunie 2026 18:40:06
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>

using namespace std;

const int mod = 19994993;

long long exp_log_rec(long long x, long long n) {
    if (n == 0) return 1;

    if (n % 2 == 0) {
        return exp_log_rec((x * x) % mod, n / 2) % mod;
    } 
    else {
        return (x * exp_log_rec((x * x) % mod, n / 2)) % mod;
    }
}

int main() {

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

    long long n, p;
    fin >> n >> p;

    fout << exp_log_rec(n, p) << "\n";

    fin.close();
    fout.close();
    return 0;
}