Pagini recente » Cod sursa (job #1485774) | Cod sursa (job #2441713) | Cod sursa (job #3309407) | Cod sursa (job #3325521) | Cod sursa (job #3356420)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int extgcd(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
int x1, y1;
int d = extgcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
int main(void)
{
int a, b, c, t, x, y, res;
fin >> t;
for (int i = 0; i < t; i++)
{
fin >> a >> b >> c;
res = extgcd(a, b, x, y);
if (c % res != 0)
{
fout << "0 0" << endl;
continue;
}
x *= c / res;
y *= c / res;
fout << x << " " << y << endl;
}
return 0;
}