Cod sursa(job #3221798)

Utilizator Radu_BicliBiclineru Radu Radu_Bicli Data 8 aprilie 2024 09:00:27
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;

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int t, a, b, c, d, x, y;

static inline int Euclid(int a, int b, int &x, int &y) {
    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    else {
        int x1, y1, d;
        d = Euclid(b, a % b, x1, y1);

        x = y1;
        y = x1 - (a / b) * y1;
        return d;
    }
}

int main() {
    fin >> t;
    while(t--) {
        fin >> a >> b >> c;

        d = Euclid(a, b, x, y);

        if(c % d != 0) fout << "0 0\n";
        else fout << x * (c / d) << " " << y * (c / d) << "\n";
    }

    return 0;
}