Cod sursa(job #398323)

Utilizator mordredSimionescu Andrei mordred Data 18 februarie 2010 14:47:32
Problema Algoritmul lui Euclid extins Scor 100
Compilator c Status done
Runda Arhiva educationala Marime 0.75 kb
// Simionescu Andrei, 2/18/2010
// http://infoarena.ro/problema/euclid3
// Dificultate: EASY
// Categorii: -

#include <stdio.h>

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


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

 return 0;
}