Cod sursa(job #2974456)

Utilizator cristiWTCristi Tanase cristiWT Data 4 februarie 2023 09:38:33
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <bits/stdc++.h>

using namespace std;

int tc;

void euclid(int a, int b, int &d, int &x, int &y) {
    if (!b)
        d = a, x = 1, y = 0;
    else {
        int x0, y0;
        euclid(b, a % b, d, x0, y0);
        x = y0;
        y = x0 - (a / b) * y0;
    }
}

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    int x = 0, y = 0, d = 0;
    euclid(a, b, d, x, y);
    if (c % d) cout << "0 0\n";
    else cout << a * (c / d) << ' ' << b * (c / d) << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);

    cin >> tc;
    while (tc--) {
        solve();
    }
}