Cod sursa(job #3340854)

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

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

    return d;
}

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;

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

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

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

    return 0;
}