Cod sursa(job #2900037)

Utilizator matwudemagogul matwu Data 9 mai 2022 22:48:22
Problema Invers modular Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int n, a, b, c;
int gcd(int a, int b, int &x, int &y){

    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    else{
        int x1 , y1;
        int g = gcd(b, a % b, x1, y1);

        x = y1;
        y = x1 - y1 * (a / b);
        return g;
    }
}
int main(){

  fin >> a >> b;
  int x, y;

  gcd(a, b, x, y);
  fout << x;
}