Cod sursa(job #2503915)

Utilizator ElizaTElla Rose ElizaT Data 3 decembrie 2019 22:13:31
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;

int gcdExtended(int a, int b, int &x, int &y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int gcd = gcdExtended(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return gcd;
}
int main() {
    ifstream fin("euclid3.in");
    ofstream fout("euclid3.out");
    int x,y,a,b,c,n,nr;
    fin >> n;
    for (int i = 0;i < n;i++) {
        fin >> a >> b >> c;
        nr = gcdExtended(a, b, x, y);
        if (c % nr)
            fout << "0 0" << '\n';
        else
            fout << x * (c / nr) << " " << y * (c / nr) << '\n';
    }
    return 0;
}