Cod sursa(job #1713565)

Utilizator S4lexandruAlexandru Stefanica S4lexandru Data 5 iunie 2016 22:46:48
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <fstream>


int gcdExt(int a, int b, int& x, int& y) {
    if (!b) {
        x = 1;
        y = 0;
        return a;
    }
    else {
        int x0, y0, d;
        
        d = gcdExt (b, a % b, x0, y0);

        x = y0;
        y = x0 - (a / b) * y0;

        return d;
    }
}

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

    int T, a, b, c, d, x, y;

    for (in >> T; T; --T) {
        in >> a >> b >> c;

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

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

    return 0;
}