Cod sursa(job #2440737)

Utilizator katanau26@yahoo.comIonut Barbu [email protected] Data 19 iulie 2019 11:39:21
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <iostream>
#include <fstream>

using namespace std;

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

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

int main()
{
    int a, b, c, d, x, y, T;

    fin >> T;
    for (size_t i = 0; i < T; i++)
    {
        fin >> a >> b >> c;
        gcdExt(a, b, d, x, y);
        cout <<a<<" "<<b<<" "<< c<< " " << d << " " << x << " " << y << endl;
        if(c % d)
            fout << "0 0 \n";
        else
            fout << x * (c / d) << " " << y * (c / d) << "\n";        
    }

    return 0;
}