Cod sursa(job #1033012)

Utilizator TheNechizFMI Razvan Birisan TheNechiz Data 16 noiembrie 2013 12:36:55
Problema Invers modular Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
# include <fstream>
# define ll long long
using namespace std;

ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A,N;

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

int main()
{
    ll X,Y;
    fin >> A >> N;
    euclid(X,Y,A,N);

    if( X <= 0 ) X = N + X%N;

    fout << X;

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