Pagini recente » Cod sursa (job #1985869) | Cod sursa (job #2895129) | Cod sursa (job #1304438) | Cod sursa (job #137895) | Cod sursa (job #2086809)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
void EuclidExtins(int a, int b, int &d, int &x, int &y)
{
int x1 = 0, y1 = 1;
x = 1, y = 0;
while(b != 0)
{
int q = a / b;
int r = a % b;
a = b;
b = r;
int x0 = x - x1 * q;
int y0 = y - y1 * q;
x = x1;
y = y1;
x1 = x0;
y1 = y0;
}
d = a;
}
int main()
{
int n;
f >> n;
while(n--)
{
int a, b, c, d, x, y, k;
f >> a >> b >> c;
EuclidExtins(a, b, d, x, y);
if(c % d != 0)g << "0 0\n";
else
{
k = c / d;
x *= k;
y *= k;
g << x << ' ' << y << '\n';
}
}
return 0;
}