Cod sursa(job #2873557)

Utilizator AlexMoto2006Motoasca Alexandru-Lucian AlexMoto2006 Data 19 martie 2022 10:55:33
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>
typedef long long ll;

using namespace std;

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

ll euclid(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    else
    {
        ll x1, y1,ss;
        ss=euclid(b, a % b, x1, y1);
        x = y1;
        y = x1 - a / b * y1;
        return ss;
    }
}

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