Cod sursa(job #3121107)

Utilizator BuzdiBuzdugan Rares Andrei Buzdi Data 10 aprilie 2023 19:11:14
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <fstream>

using namespace std;

ifstream cin("euclid3.in");
ofstream cout("euclid3.out");

int T;

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

    int x0, y0;
    Euclid(b, a % b, x0, y0, d);

    x = y0;
    y = x0 - (a / b) * y0;
}

int main()
{
    cin >> T;
    while(T--)
    {
        int a, b, c;
        cin >> a >> b >> c;
        
        int x, y, d;
        Euclid(a, b, x, y, d);

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

    return 0;
}