Pagini recente » Cod sursa (job #2970692) | Cod sursa (job #1100608) | Borderou de evaluare (job #2100028) | Cod sursa (job #2242101) | Cod sursa (job #2641022)
#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);
int main()
{
int T;
fin >> T;
for (int i = 1, a, b, c; i <= T; ++i)
{
fin >> a >> b >> c;
int x, y, d;
euclid(a, b, &d, &x, &y);
if ((c % d) == 0)
{
int aux = c / d;
fout << x * aux << ' ' << y * aux << '\n';
}
else
{
fout << "0 0\n";
}
}
fin.close();
fout.close();
return 0;
}
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;
}
}