Pagini recente » Cod sursa (job #1238636) | Cod sursa (job #909974) | Cod sursa (job #2343219) | Cod sursa (job #2415458) | Cod sursa (job #2192004)
#include <stdio.h>
#include <stdlib.h>
int cmmdc( int a, int b ) {
int r;
while ( b > 0 ) {
r = a % b;
a = b;
b = r;
}
return a;
}
void euclidE( int a, int b, int *x, int *y ) {
int x0, y0;
if ( b == 0 ) {
*x = 1;
*y = 0;
} else {
euclidE( b, a % b, &x0, &y0 );
*x = y0;
*y = x0 - ( a / b ) * y0;
}
}
int main() {
FILE *fin, *fout;
int t, a, b, c, d, x, y, i;
fin = fopen( "euclid3.in", "r" );
fout = fopen( "euclid3.out", "w" );
fscanf( fin, "%d", &t );
for ( i = 0; i < t; i++ ) {
fscanf( fin, "%d%d%d", &a, &b, &c );
d = cmmdc( a, b );
if ( c % d == 0 ) {
euclidE( a, b, &x, &y );
fprintf( fout, "%d %d\n", x * ( c / d ) , y * ( c / d ) );
} else {
fprintf( fout, "0 0\n" );
}
}
fclose( fin );
fclose( fout );
return 0;
}