Cod sursa(job #2515963)

Utilizator Narcis09Grecu Narcis Narcis09 Data 29 decembrie 2019 21:11:48
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 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;  
}