Cod sursa(job #1249105)

Utilizator okros_alexandruOkros Alexandru okros_alexandru Data 26 octombrie 2014 15:24:34
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include <fstream>

using namespace std;

int d;

int cmmdc(int a, int b, int & x, int & y) {

    if(b == 0) {
        d = a;
        x = 1;
        y = 0;
    } else {

        cmmdc(b, a % b, x, y);

        int tmp = x;
        x = y;
        y = tmp - (a / b) * y;

    }

}
int main() {

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

    ifstream in("euclid3.in");
    ofstream out("euclid3.out");

    in >> T;

    while(T--) {

        in >> a >> b >> c;

        cmmdc(a, b, x, y);

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

        }

    in.close();
    out.close();

    return 0;

}