Cod sursa(job #1373014)

Utilizator oprea1si2si3Oprea Sebastian oprea1si2si3 Data 4 martie 2015 16:20:44
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>
using namespace std;

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

int x, y, d;

void EE(int a, int b, int &x, int &y) {
    if (b == 0) {
        d = a;
        x = 1;
        y = 0;
        return ;
    }
    EE(b, a % b, x, y);
    int aux = x;
    x = y;
    y = aux - y * (a / b);
}

int main() {
    int t, a, b, c;
    in >> t;
    while (t--) {
        in >> a >> b >> c;
        x = 1;
        y = 0;
        EE(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;
}