Cod sursa(job #2868865)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 11 martie 2022 11:09:55
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

using ll = long long;

inline ll gcdEx(ll a, ll b, ll &x, ll &y){
    if(b == 0){
        x = 1, y = 0;
        return a;
    }
    ll div = gcdEx(b, a % b, x, y);
    ll x1 = y;
    ll y1 = x - (a / b) * y;
    x = x1, y = y1;
    return div;
}

int main()
{
    int t;
    fin >> t;

    while(t--){
        ll a, b, c;
        fin >> a >> b >> c;

        ll x, y;
        ll d = gcdEx(a, b, x, y);
        if(c % d != 0)
            fout << "0 0\n";
        else fout << x * (c / d) << ' ' << y * (c / d) << '\n';

    }
    return 0;
}