Cod sursa(job #2978910)

Utilizator CobzaruAntonioCobzaru Paul-Antonio CobzaruAntonio Data 14 februarie 2023 17:07:03
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.86 kb
#include <fstream>
#define ll long long
using namespace std;
ifstream cin ("euclid3.in");
ofstream cout ("euclid3.out");
void cmmdc (ll x,ll y,ll &d)
{
    if (y== 0)
        d = x;
    else
        cmmdc(y,x%y,d);
}
void euclid (ll x,ll y,ll &a,ll &b)
{
    if (y == 0)
    {
        a = 1;
        b = 0;
    }
    else
    {
        ll x1,y1;
        euclid(y,x%y,x1,y1);
        a = y1;
        b = x1 - (x/y)*y1;
    }
}
void solve ()
{
    ll x,y,c;
    cin >> x >> y >> c;
    ll a,b,d;
    cmmdc(x,y,d);
    if (c%d!=0)
    {
        cout << "0 0" << '\n';
        return;
    }
    euclid(x,y,a,b);
    cout << a*c/d << ' ' << b*c/d << '\n';
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t)
    {
        t--;
        solve();
    }
    return 0;
}