Cod sursa(job #1006135)

Utilizator florin.elfusFlorin Elfus florin.elfus Data 6 octombrie 2013 14:57:14
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <stdio.h>

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

int main() {
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);

    int T;
    scanf("%d", &T);
    for (int test = 1; test <= T; ++test) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        int x, y, d = gcd(a, x, b, y);
        if (c % d)
            printf("0 0\n");
        else
            printf("%d %d\n", x * (c / d), y * (c / d));
    }

    return 0;
}