Pagini recente » Cod sursa (job #1065683) | Cod sursa (job #3039790) | Cod sursa (job #3256565) | Cod sursa (job #1759630) | Cod sursa (job #2089861)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("euclid3.in");
ofstream fout ("euclid3.out");
int n, a, b, c, x, y, d;
void euclid (int a, int b, int &d, int &x, int &y){
int x0 = 1, y0 = 0, cat;
int x1 = 0, y1 = 1;
if (a % b == 0) {
x = 0; y = 1;
d = b;
return;
}
while (b != 0) {
cat = a / b;
int r = a % b;
a = b;
b = r;
x = x0 - x1 * cat;
y = y0 - y1 * cat;
x0 = x1;
x1 = x;
y0 = y1;
y1 = y;
}
d = a;
}
int main()
{
fin >> n;
for (int i = 1; i <= n; i++) {
fin >> a >> b >> c;
euclid (a, b, d, x, y);
if (c % d != 0)
fout << "0 0\n";
else {
int k = c / d;
x *= k;
y *= k;
fout << x << " " << y << "\n";
}
}
return 0;
}