Pagini recente » Cod sursa (job #3148368) | Cod sursa (job #2893930) | Cod sursa (job #2965500) | Cod sursa (job #1081283) | Cod sursa (job #3227630)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin( "euclid3.in");
ofstream fout( "euclid3.out");
void EuclidExtins(int a, int b, int *d, int *x, int *y)
{
int x0 = 0, y0 = 0;
if (b == 0) {
*d = a;
*x = 1;
*y = 0;
} else {
EuclidExtins(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main()
{
int a, b, c, nr;
fin >> nr;
for(int i = 1; i <= nr; i++) {
fin >> a >> b >> c;
int d, x, y;
EuclidExtins(a, b, &d, &x, &y);
if (c % d != 0) {
fout << "0 0\n";
} else {
fout << (c / d * x) << ' ' << (c / d * y) << '\n';
}
}
return 0;
}