Cod sursa(job #3000605)

Utilizator Vincent47David Malutan Vincent47 Data 12 martie 2023 17:03:08
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, c, a, b;

void euclid(int a, int b, int &d, int &x, int &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        d = a;
    }
    else
    {
        int x0, y0;
        euclid(b, a % b, d, x0, y0);
        x = y0;
        y = x0 - (a / b) * y0;
    }
}

int main()
{

    cin >> t;
    for (int i = 1; i <= t; ++i)
    {
        cin >> a >> b >> c;
        int d, x, y;
        euclid(a, b, d, x, y);
        if (c % d != 0)
            cout << '0' << ' ' << '0' << '\n';
        else cout << x * (c / d) << ' ' << y * (c / d) << '\n';
    }
    return 0;
}