Cod sursa(job #3284715)

Utilizator domdiridomdidomDominik domdiridomdidom Data 12 martie 2025 09:23:00
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>

long long modInv(long long a, long long b, long long & x, long long & y){
    if(a == 0){
        x = 0;
        y = 1;
        return b;
    }
    long long x1, y1, lnko = modInv(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return lnko;
}

int main(){
    std::ifstream bem("inversmodular.in");
    long long a, mod, x, y;
    bem >> a >> mod;
    bem.close();
    modInv(a, mod, x, y);
    while(x < 0) x += mod;
    std::ofstream kim("inversmodular.out");
    kim << x;
    kim.close();
    return 0;
}