Cod sursa(job #2689622)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 21 decembrie 2020 17:51:31
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <fstream>

using namespace std;

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

int n, c;

void extendedGCD(int a, int b, int &x, int &y) {
    if(b == 0) {
        x = 1, y = 0;
        c = a;
        return;
    }

    int x0, y0;
    extendedGCD(b, a % b, x0, y0);
    x = y0, y = x0 - (a/b) * y0;
}

int main()
{
    fin >> n;

    while(n--) {
        int a, b, d, x, y;
        fin >> a >> b >> d;

        extendedGCD(a, b, x, y);

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