Pagini recente » Cod sursa (job #844416) | Cod sursa (job #2318530) | Cod sursa (job #415691) | Cod sursa (job #1633199) | Cod sursa (job #2662719)
#include <fstream>
using namespace std;
ifstream fin( "euclid3.in" );
ofstream fout( "euclid3.out" );
void euclid(int a, int b, int *d, int *x, int *y) {
if (b == 0) {
*d = a;
*x = 1;
*y = 0;
} else {
int x0, y0;
euclid(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main() {
int q, a, b, c, z, x, y;
fin >> q;
while( q-- ){
fin >> a >> b >> c;
euclid(a, b, &z, &x, &y);
if( c % z != 0 )
fout << "0 0\n";
else
fout << (c / z) * x << " " << (c / z) * y << "\n";
}
return 0;
}