Cod sursa(job #2375401)

Utilizator EricEric Vilcu Eric Data 8 martie 2019 08:55:02
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.41 kb
#include <iostream>
#include <fstream>
#define l long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
l a,b,x,y;
l nsh(l a,l b,l&x,l&y)
{
    if(b==0)
    {
        x=1;y=0;return a;
    }
    l x0,y0,d;
    d=nsh(b,a%b,x0,y0);
    x=y0;
    y=x0-(a/b)*y0;
    return d;
}
int main()
{
    f>>a>>b;
    nsh(a,b,x,y);
    if(x<0)x=b+x%b;
    g<<x;
}