Cod sursa(job #1800479)

Utilizator gamanedyGaman Eduard-Marian gamanedy Data 7 noiembrie 2016 20:05:04
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>

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

void gcdextins(long long a, long long b,long long &x, long long&y, long long d)
{
    if(b==0)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        long long x0,y0,d0;
        gcdextins(b,a%b,x0,y0,d0);
        d=d0;
        x=y0;
        y=x0-(a/b)*y0;
    }
}
long long a,n,x,y;
int main()
{
    fin>>a>>n;
    gcdextins(a,n,x,y,1);
    if(x<0)
    {
        x=x+n;
    }
    fout<<x;
    return 0;
}