Cod sursa(job #3356503)

Utilizator Car13Carmi Carabas Car13 Data 1 iunie 2026 21:37:21
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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


int main(){
    int a, n;
    fin >> a >> n;
    int mod = n, y0 = 0, y, y1 = 1, r, c;
    while (a != 0)
    {
        r = n % a;
        c = n / a;
        n = a;
        a = r;
        y = y0 - c * y1;
        y0 = y1;
        y1 = y;
    }
    while(y0 < 0){
        y0 += mod;
    }
    fout << y0;
    fin.close();
    fout.close();
    return 0;
}