Cod sursa(job #3151206)

Utilizator Chris_BlackBlaga Cristian Chris_Black Data 20 septembrie 2023 09:49:49
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.86 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;


ll euclid_extins(ll a, ll b, ll& d, ll& x, ll& y)
{
    if(!b)
    {
        x = 1, y = 0, d = a;
        return a;
    }

    ll x0, y0;

    ll aux = euclid_extins(b, a % b, d, x0, y0);

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

    return aux;
}

void solve()
{
    ll a, b, c, x, y;
    cin >> a >> b >> c;

    ll cmmdc;
    euclid_extins(a, b, cmmdc, x, y);

    if(c % cmmdc != 0)
    {
        cout << "0 0\n";
        return;
    }

    a = a * c / cmmdc;
    b = b * c / cmmdc;

    euclid_extins(a, b, c, x, y);

    cout << x * c / cmmdc << ' ' << y * c / cmmdc << '\n';
}

int main()
{
//    freopen("euclid3.in", "r", stdin);
//    freopen("euclid3.out", "w", stdout);

    int t;
    cin >> t;
    while(t --)
        solve();
    return 0;
}