Cod sursa(job #591554)

Utilizator cmiNCosmin Poieana cmiN Data 24 mai 2011 18:38:17
Problema Algoritmul lui Euclid extins Scor 100
Compilator c Status done
Runda Arhiva educationala Marime 0.78 kb
#include <stdio.h>

inline void func(int a, int b, int c)
{
    int x1, x2, y1, y2, tmp;
    x1 = y2 = 1;
    x2 = y1 = 0;
    while (b) {
        x1 -= (a / b) * x2;
        y1 -= (a / b) * y2;
        tmp = x1;
        x1 = x2;
        x2 = tmp;
        tmp = y1;
        y1 = y2;
        y2 = tmp;
        tmp = a;
        a = b;
        b = tmp % b;
    }
    if (c % a) {
        printf("0 0\n");
    } else {
        printf("%d %d\n", x1 * (c / a), y1 * (c / a));
    }
}

int main()
{
    int a, b, c, t;
    freopen("euclid3.in", "rt", stdin);
    freopen("euclid3.out", "wt", stdout);
    scanf("%d", &t);
    while (t-- > 0) {
        scanf("%d %d %d", &a, &b, &c);
        func(a, b, c);
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}