Cod sursa(job #2164065)

Utilizator AndreiBadescuBadescu Andrei-Octavian AndreiBadescu Data 12 martie 2018 21:19:37
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>

using namespace std;

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

int x, y, a, n;

void gcd ( int a, int b, int &x, int &y )
{
    if ( b == 0 )
    {
        x = 1;
        y = 0;
        return;
    }

    int x0, y0, t = a / b;

    gcd ( b, a - b * t, x0, y0 );

    x = y0;
    y = x0 - t * y0;
}

int main()
{
    fin >> a >> n;

    gcd ( a, n, x, y );

    fout << x;
}