Cod sursa(job #2142029)

Utilizator EclipseTepes Alexandru Eclipse Data 24 februarie 2018 18:01:21
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <iostream>
#include <fstream>

using namespace std;

typedef long long int lint;
unsigned short int T, i, j;
lint aa, bb, cc;
lint t1, t2, t3;

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

lint ExtendedEuclid(lint a, lint b, lint &x, lint &y) {
    if (!b) {
        x = 1, y = 0;
        return a;
    } else {
        lint x0, y0, d;
        d = ExtendedEuclid(b, a % b, x0, y0);
        x = y0;
        y = x0 - y0 * (a/b);
        return d;
    }
}

int main()
{
    fin >> T;
    for (i = 1; i <= T; i++) {
        fin >> aa >> bb >> cc;
        t1 = ExtendedEuclid(aa, bb, t2, t3);
        if (cc % t1) fout << "0 0\n";
        else fout << t2 * (cc / t1) << " " << t3 * (cc / t1) << "\n";
    }
    return 0;
}