Cod sursa(job #772160)

Utilizator SchumiDumitru Andrei Georgian Schumi Data 28 iulie 2012 14:36:17
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <cstdio>

using namespace std;

int n, a, b, c, x, y, c2;

void gcd(int a, int b, int &x, int &y, int &c)
{
    if(b == 0) {
        x = 1;
        y = 0;
        c = a;
        return;
    }
    
    int x2, y2;
    gcd(b, a % b, x2, y2, c);
    x = y2;
    y = x2 - y2 * (a / b);

}

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

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