Cod sursa(job #2728946)

Utilizator Leonard123Mirt Leonard Leonard123 Data 23 martie 2021 21:15:03
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.47 kb
#include<fstream>
using namespace std;

ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");

void euclid(int a, int b, int *x, int *y) {
    if (b == 0) {
        *x = 1;
        *y = 0;
    } else {
        int x0, y0;
        euclid(b, a % b, &x0, &y0);
        *x = y0;
        *y = x0 - (a / b) * y0;
    }
}

int main() {
    int a, b, c, x, y;
    cin >> a >> b; 
    c = 1;
    euclid(a, b, &x, &y);
    while (x < 0) 
        x += b;
    
    cout << x;
}