Cod sursa(job #2673882)

Utilizator Iulia14iulia slanina Iulia14 Data 18 noiembrie 2020 08:39:09
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <fstream>

using namespace std;
ifstream cin ("euclid3.in");
ofstream cout ("euclid3.out");
int euclid(int a, int b, int &x, int &y)
{
    int x0, y0, d;
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    d = euclid(b, a % b, x0, y0);
    x = y0;
    y = x0 - (a / b) * y0;
    return d;
}
int main()
{
    int t, a, c, b;
    cin >> t;
    while (t--)
    {
        cin >> a >> b >> c;
        int x, y;
        int d = euclid(a, b, x, y);
        if (c % d)
            cout << "0 0";
        else
            cout << x * c / d << " " << y * c / d;
        cout << '\n';
    }
    return 0;
}