Cod sursa(job #3214565)

Utilizator Maftei_TudorMaftei Tudor Maftei_Tudor Data 14 martie 2024 11:02:53
Problema Algoritmul lui Euclid extins Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <iostream>

#define int long long

using namespace std;

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

int32_t main()
{
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);
    cin.tie(nullptr)->sync_with_stdio(0);

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