Cod sursa(job #2974514)

Utilizator Hackerul_GoguIordache Alexandru Hackerul_Gogu Data 4 februarie 2023 10:03:48
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <bits/stdc++.h>

using namespace std;
#define int long long
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;
    }
}

signed main()
{
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);
    cin.tie(nullptr) -> sync_with_stdio(false);
    int T, a, b, c;
    cin >> T;
    while(T--) {
        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 << x * (c / d) << ' ' << y * (c / d) << '\n';
    }
}