Cod sursa(job #2056175)

Utilizator andrei2000mAndrei Moldoveanu andrei2000m Data 4 noiembrie 2017 09:42:47
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int main()
{   int a,aux,n,x0,x1,r,c,x;
    f>>a>>n;
    x0=1;x1=0;
    aux=n;
    while (n!=0)
    {
        r=a%n;
        c=a/n;
        a=n;
        n=r;
        x=x0-c*x1;
        x0=x1;
        x1=x;
    }
    if (x0<0) g<<x0+aux;
    else g<<x0;
    return 0;
}