Cod sursa(job #3226742)

Utilizator _andrei4567Stan Andrei _andrei4567 Data 22 aprilie 2024 18:02:40
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <iostream>

using namespace std;

void euclid_extins (int a, int b, int &d, int &x, int &y)
{
    if (!b)
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x1, y1;
    euclid_extins (b, a % b, d, x1, y1);
    x = y1;
    y = x1 - (a / b) * y1;
}

int a, b, c, t;

void solve ()
{
    cin >> a >> b >> c;
    int x, y, d;
    x = y = d = 0;
    euclid_extins (a, b, d, x, y);
    if ((c % d) != 0)
        cout << "0 0\n";
    else
        cout << x * (c / d) << ' ' << y * (c / d) << '\n';
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    for (cin >> t; t--; solve());
    return 0;
}