Cod sursa(job #2215638)

Utilizator vladm98Munteanu Vlad vladm98 Data 22 iunie 2018 20:53:07
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <bits/stdc++.h>

using namespace std;

void extindedEuclid (long long x, long long y, long long &a, long long &b, long long &d) {
    if (y == 0) {
        d = x;
        a = 1;
        b = 0;
        return ;
    }
    extindedEuclid(y, x % y, a, b, d);
    long long newA = b;
    long long newB = a - b * (x / y);
    a = newA;
    b = newB;
}

int main()
{
    freopen ("euclid3.in", "r", stdin);
    freopen ("euclid3.out", "w", stdout);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        long long x, y, c, a, b, gcd;
        cin >> x >> y >> c;
        extindedEuclid(x, y, a, b, gcd);
        if (c % gcd) {
            cout << "0 0\n";
        }
        else {
            cout << a * (c / gcd) << ' ' << b * (c / gcd) << '\n';
        }
    }
    return 0;
}