Cod sursa(job #2924755)

Utilizator Andrei137Neculae Andrei-Fabian Andrei137 Data 10 octombrie 2022 00:32:49
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <fstream>

std::ifstream in("euclid3.in");
std::ofstream out("euclid3.out");

void euclid(int a, int b, int &d, int &x, int &y)
{
    if (!b)
    {
        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 a, b, c, d, x, y, n;
    in >> n;
    while (n--)
    {
        in >> a >> b >> c;
        euclid(a, b, d, x, y);
        if (c % d != 0)
            out << "0 0\n";
        else
            out << x * (c / d) << ' ' << y / (c / d) << '\n';
    }
    in.close();
    out.close();
    return 0;
}