Cod sursa(job #1606304)

Utilizator dinu_sergiuDinu Sergiu Andrei dinu_sergiu Data 20 februarie 2016 09:14:41
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <fstream>

using namespace std;

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

void Euclid(int a, int b, int &d, int &x, int &y)
{
    if(b==0) { d=a; x=1; y=0; }
    else
    {
        int x0, y0;
        Euclid(b, a%b, d, x0, y0);
        x=y0;
        y=x0-(a/b)*y0;
    }
}

int main()
{
    int T, a, b, x, y, d, i, c;
    fin>>a>>b;
    Euclid(a, b, d, x, y);
    //if(c%d!=0)
      //      fout<<"0 0\n";
    //    else fout<<x*(c/d)<<" "<<y*(c/d)<<"\n";
    fout<<x<<"\n";
    fin.close();
    fout.close();
    return 0;
}