Cod sursa(job #1360073)

Utilizator mirceadinoMircea Popoveniuc mirceadino Data 25 februarie 2015 11:24:59
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include<cstdio>
#include<string>

using namespace std;

#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "euclid3";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif

typedef long long int lld;

int T;

lld euclid(lld a, lld b, lld &x, lld &y) {
    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }

    lld x0, y0;
    lld d = euclid(b, a % b, x0, y0);

    x = y0;
    y = x0 - (a / b) * y0;

    return d;
}

int main() {
    lld a, b, c, d, x, y;

    freopen(inputFile.c_str(), "r", stdin);
    freopen(outputFile.c_str(), "w", stdout);

    scanf("%d", &T);

    while(T--) {
        scanf("%lld%lld%lld", &a, &b, &c);

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

        if(c % d)
            x = y = 0;
        else {
            x *= (c / d);
            y *= (c / d);
        }

        printf("%lld %lld\n", x, y);
    }

    return 0;
}