Cod sursa(job #3258178)

Utilizator mihai.25Calin Mihai mihai.25 Data 21 noiembrie 2024 15:14:21
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>

using namespace std;

ifstream cin ("euclid3.in");

ofstream cout ("euclid3.out");

void euclid_extins (int a, int b, int &d, int &x, int &y) {

    if (!b) {

        d = a;

        x = 1;

        y = 0;
    }
    else {

        int x0, y0;

        euclid_extins (b, a % b, d, x0, y0);

        x = y0;

        y = x0 - a / b * y0;
    }
}

int main () {

    int t;

    cin >> t;

    while (t--) {

        int a, b, c;

        cin >> a >> b >> c;

        int d = 0, x = 0, y = 0;

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

        if (c % d)
            cout << "0 0\n";
        else
            cout << x * (c / d) << ' ' << y * (c / d) << '\n';
    }

    return 0;
}