Pagini recente » Cod sursa (job #2485155) | Cod sursa (job #902003) | Cod sursa (job #2394898) | Cod sursa (job #1825317) | Cod sursa (job #2194680)
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("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 t, a, b, c;
in >> t;
while(t--) {
in >> a >> b >> c;
int d, x, y;
euclidExtins(a, b, d, x, y);
if(c%d == 0) {
x *= c/d;
y *= c/d;
out << x << ' ' << y << '\n';
} else out << "0 0\n";
}
return 0;
}