Cod sursa(job #3283420)

Utilizator Barbu_MateiBarbu Matei Barbu_Matei Data 9 martie 2025 15:06:13
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <bits/stdc++.h>
using namespace std;

int t;

int gcd(int a, int b, int &x, int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int x1, y1;
    int d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

int main() {
    ifstream cin("euclid3.in");
    ofstream cout("euclid3.out");
    cin >> t;
    while (t--) {
        int a, b, c;
        cin >> a >> b >> c;
        int x, y;
        int d = gcd(a, b, x, y);
        if (c % d != 0) {
            cout << "0 0\n";
        } else {
            cout << x * (c / d) << " " << y * (c / d) << "\n";
        }
    }
}