Cod sursa(job #2821549)

Utilizator Toaster_KeyboardMihaescu Vlad-Mihai Toaster_Keyboard Data 22 decembrie 2021 18:10:11
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#pragma region
#include <bits/stdc++.h>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
#pragma endregion

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;
}

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

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int t = 1;  fin >> t;
    while (t--) {
        solve();
    }

    return 0;
}