Cod sursa(job #1412354)

Utilizator crysstyanIacob Paul Cristian crysstyan Data 1 aprilie 2015 11:41:27
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include <fstream>
#define ll long long

using namespace std;

ifstream f("inversmodular.in");
ofstream g("inversmodular.out");

ll a, b, x, y;

ll euclid(ll a, ll b, ll &x, ll &y)
{
    if (b==0)
    {
        x=1;
        y=0;
        return a;
    }
    else
    {
        ll x0, y0, d;
        d=euclid(b,a%b,x0,y0);
        x=y0;
        y=x0-(a/b)*y0;
        return d;
    }
}

int main()
{
    f>>a>>b;
    euclid(a,b,x,y);
    while (x<0) x+=b;
    g<<x<<'\n';
    return 0;
}