Cod sursa(job #1561011)

Utilizator alexandru92alexandru alexandru92 Data 3 ianuarie 2016 16:19:24
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>

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

int main() {
    int T;
    std::ifstream in{"euclid3.in"};
    std::ofstream out{"euclid3.out"};

    for (in >> T; T; --T) {
        int x, y, a, b, c, d;
        in >> a >> b >> c;
        gcd (a, b, d, x, y);

        if (c % d) {
            out << "0 0\n";
        }
        else {
            out << ((c / d) * x) << ' ' << ((c / d) * y) << '\n';
        }
    }

    return 0;
}