Cod sursa(job #2066415)

Utilizator alexpetrescuAlexandru Petrescu alexpetrescu Data 14 noiembrie 2017 23:11:44
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>

using namespace std;

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

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

int main() {
    int t;
    fin >> t;

    for (; t; t--) {
        int a, b, c;
        fin >> a >> b >> c;

        int x, y, d;
        euclid(a, b, d, x, y);

        if (c % d) x = y = 0;
        fout << x * (c / d) << ' ' << y * (c / d) << '\n';
    }

    return 0;
}