Cod sursa(job #165698)

Utilizator tm_raduToma Radu tm_radu Data 26 martie 2008 16:43:06
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <stdio.h>

int t;

int GCD(int a, int b, int &x, int &y);

int main()
{
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);
    scanf("%d", &t);
    while ( t )
    {    
        int a, b, c, x, y, d;
        scanf("%d %d %d", &a, &b, &c);
        d = GCD(a, b, x, y);
        
        if ( c % d != 0 ) printf("0 0\n");
        else              printf("%d %d\n", x *(c/d), y*(c/d));
        t--;
    }    
    return 0;
}

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