Pagini recente » Cod sursa (job #2831454) | Cod sursa (job #372485) | Cod sursa (job #2126232) | Cod sursa (job #35485) | Cod sursa (job #2649938)
#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;
*y = 0;
*x = 1;
}
else
{
int x0, y0;
euclid(b, a%b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main(void)
{
int a, b, d, x, y, c, n;
fin >> n;
for (int i = 0; i < n; i++)
{
fin >> a >> b >> c;
euclid(a, b, &d, &x, &y);
if (c % d == 0)
{
int cc;
cc = c / d;
fout << cc * x <<' '<< cc * y <<'\n';
}
else
fout << 0 <<' '<< 0 << '\n';
}
return 0;
}