Cod sursa(job #1174034)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 21 aprilie 2014 18:40:01
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>

using namespace std;

int Euclid(const int a, const int b, int &x, int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int nx, ny;
    int d = Euclid(b, a % b, nx, ny);
    x = ny;
    y = nx - (a / b) * ny;
    return d;
}

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