Cod sursa(job #1460951)

Utilizator borcanirobertBorcani Robert borcanirobert Data 14 iulie 2015 14:06:44
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <fstream>
using namespace std;

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

int A, N;

void EuclidExtins( long long& x, long long& y, int a, int b );

int main()
{
    long long x, y;

    fin >> A >> N;
    EuclidExtins( x, y, A, N );

    fout << x << '\n';

    fin.close();
    fout.close();
    return 0;
}

void EuclidExtins( long long& x, long long& y, int a, int b )
{
    if ( b == 0 )
        x = 1, y = 0;
    else
    {
        EuclidExtins( x, y, b, a % b );
        long long aux = x;
        x = y;
        y = aux - ( a / b ) * y;
    }
}