Cod sursa(job #3311358)

Utilizator AndreiNicolaescuEric Paturan AndreiNicolaescu Data 21 septembrie 2025 14:39:09
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>
#define cin ci
#define cout co
using namespace std;
ifstream cin("euclid3.in");
ofstream cout("euclid3.out");
int n, a, b, c;
int gcd(int &x, int &y, int a, int b)
{
    if(b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    int d = gcd(x, y, b, a % b);
    int aux = x;
    x = y;
    y = aux - y * (a / b);
    return d;
}
int main()
{
    cin >> n;
    while(n--)
    {
        int x, y, d;
        cin >> a >> b >> c;
        d = gcd(x, y, a, b);
        if(c % d)
            cout << 0 << " " << 0 << '\n';
        else
            cout << x * (c / d) << " " << y * (c / d) << '\n';
    }
    return 0;
}