Cod sursa(job #3340852)

Utilizator Sabin1133Padurariu Sabin Sabin1133 Data 16 februarie 2026 19:37:10
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.86 kb
#include <fstream>

void bezout_gcd(int a, int &x, int b, int &y, int &d)
{
    int r_x, r_y;
    
    if (b == 0) {
        x = 1;
        y = 0;
        d = a;
    } else {
        bezout_gcd(b, r_x, a % b, r_y, d);

        x = r_y;
        y = r_x - (a / b) * r_y;
    }
}

int main()
{
    int n;
    std::ifstream fin("euclid3.in");
    std::ofstream fout("euclid3.out");

    fin >> n;

    for (int a, x, b, y, d, c, i = 0; i < n; ++i) {
        fin >> a >> b >> c;

        bezout_gcd(a, x, b, y, d);

        if (c > d)
            if (c % d)
                fout << "0 0\n";
            else
                fout << x * (c / d) << ' ' << y * (c / d) << '\n';
        else
            if (d % c)
                fout << "0 0\n";
            else
                fout << x * (d / c) << ' ' << y * (d / c) << '\n';
    }

    fin.close();
    fout.close();

    return 0;
}