Pagini recente » Cod sursa (job #1472299) | Cod sursa (job #1318491) | Cod sursa (job #1577195) | Cod sursa (job #2373372) | Cod sursa (job #3156933)
#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) {
if (b == 0) {
d = a;
x = 1;
y = 0;
} else {
int x0, y0;
euclidExtins(b, a%b, d, x0, y0);
x = y0;
y = x0 - a/b*y0;
}
}
int main()
{
int T, d, x, y, a, b, c;
f >> T;
while (T--) {
f >> a >> b >> c;
euclidExtins(a, b, d, x, y);
if (c%d != 0)
g << 0 << ' ' << 0 << '\n';
else
g << x*(c/d) << ' ' << y*(c/d) << '\n';
}
return 0;
}