Cod sursa(job #2254622)

Utilizator AlexAboAbogatoaie Alexandru AlexAbo Data 5 octombrie 2018 17:20:56
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <fstream>

using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
typedef long long Int;
Int n,a,x,y,cmmdc(Int,Int,Int&,Int&);
int main()
{
    f>>a>>n;
    cmmdc(a,n,x,y);
    x=x%n;
    g<<x;
    return 0;
}
Int cmmdc(Int a,Int b,Int &x, Int &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    Int X,Y,D;
    D = cmmdc(b,a%b, X,Y);
    x = Y;
    y = X-a/b*Y;
    return D;
}