Cod sursa(job #2376514)

Utilizator MarianConstantinMarian Constantin MarianConstantin Data 8 martie 2019 16:05:16
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <iostream>
#include <fstream>

using namespace std;

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

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

int main() {
    long long t, a, b, c, d, x, y;
    fin >> t;
    for (long long i = 1; i <= t; ++i) {
        fin >> a >> b >> c;
        extendedEuclidean(a, b, d, x, y);
        if (c % d)
            fout << "0 0\n";
        else
            fout << x * (c / d) << " " << y * (c / d) << "\n";
    }
    return 0;
}