Cod sursa(job #3376603)

Utilizator Mihai_OctMihai Octavian Mihai_Oct Data 18 noiembrie 2026 15:57:17
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <bits/stdc++.h>
//#include <bits/extc++.h>

using namespace std;

#define USE_STD_IO 0
#if USE_STD_IO
    #define fin  cin
    #define fout cout
#else
    ifstream fin("euclid3.in");
    ofstream fout("euclid3.out");
#endif // USE_STD_IO

static inline int Euclid(int a, int b, int& x, int& y) {
    if(0 == b) {
        x = 1;
        y = 0;
        return a;
    }
    else {
        int x0, y0;
        int d = Euclid(b, a % b, x0, y0);
        x = y0;
        y = x0 - (a / b) * y0;
        return d;
    }
}

int main() {
    #if USE_STD_IO
        ios_base::sync_with_stdio(false);
    #endif // USE_STD_IO
    fin.tie(NULL);
    fout.tie(NULL);

    int t;
    fin >> t;
    while(0 < t--) {
        int a, b, c, x, y;
        fin >> a >> b >> c;
        int d = Euclid(a, b, x, y);
        if(0 != c % d) fout << "0 0\n";
        else fout << x * (c / d) << ' ' << y * (c / d) << '\n';
    }

    return 0;
}