Pagini recente » Cod sursa (job #3291945) | Cod sursa (job #3291833) | Cod sursa (job #3291970) | Cod sursa (job #3289677) | Cod sursa (job #3293002)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
/*
a * x + b * y = d
b * x0 + (a % b) * y0 = d
a % b = a - b * c;
b * x0 + (a - b * c) * y0 = a * x + b * y
b * (x0 - y - c * y0) = a * (x - y0)
daca x - y0 = 0 atunci y = x0 - (a/b) * y0
*/
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 t, a, b, c, d, x, y;
fin >> t;
while (t--)
{
fin >> a >> b >> c;
euclid(a, b, d, x, y);
if(c % d != 0)
fout << "0 0\n";
else
fout << x * (c / d) << " " << y * (c / d) << "\n";
}
return 0;
}