Cod sursa(job #1802692)

Utilizator Andrei_CotorAndrei Cotor Andrei_Cotor Data 10 noiembrie 2016 16:25:35
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include<fstream>
using namespace std;
ifstream fi("inversmodular.in");
ofstream fo("inversmodular.out");
long long a,n,x,y,aux;

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

int main()
{
    fi>>a>>n;
    gcd(a,n);
    if(x<=0)
       x=n+x%n;
    fo<<x<<"\n";
    fi.close();
    fo.close();
    return 0;
}