Cod sursa(job #2181205)

Utilizator bebeetarepredescu bebeetare Data 21 martie 2018 15:23:07
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <fstream>

using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcd(int a, int b, int &x, int &y){
    if(b == 0)
    {
        x = 1;
        y = 0;
        return;
    }
    gcd(b, a%b, x, y);
    int aux = x;
    x = y;
    y = aux - (a/b) * y;
}
int main()
{
    int a, n;
    fin >> a >> n;
    int x = 0;
    int y = 0;
    gcd(a, n, x, y);
    while(x < 1)
    {
        x += n;
    }
    fout << x;
    return 0;
}