Cod sursa(job #3188608)

Utilizator CaldareaCiprianCaldarea Ciprian CaldareaCiprian Data 3 ianuarie 2024 15:17:44
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <iostream>


using namespace std;


void cmmdc(int a, int b, int& x, int& y, int& d)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        d = a;
        return;
    }

    int yt, xt;

    cmmdc(b, a % b, xt, yt, d);

    x = yt;
    y = xt - (a / b) * yt;
}

int main()
{
    int n, a, b, c;

    cin >> n;

    while (n--)
    {
        cin >> a >> b >> c;

        int d, x, y;
        cmmdc(a, b, x, y, d);

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

    return 0;
}