Pagini recente » Cod sursa (job #3228633) | Cod sursa (job #1534987)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int x0, y0, d;
void gcd(int a, int b) { // a > b
if (b == 0) {
d = a;
x0 = 1;
y0 = 0;
return;
} else {
int q = a/ b;
gcd(b, a%b);
int tmp = y0;
y0 = x0 - q*y0;
x0 = tmp;
return;
}
}
int main() {
ifstream fin ("euclid3.in");
ofstream fout ("euclid3.out");
int T, a,b, apos, bpos, c;
fin >> T;
for (int i = 0; i < T; i++) {
fin >> a >> b >> c;
apos = abs(a);
bpos = abs(b);
if (apos > bpos) {
gcd(apos, bpos);
} else {
gcd(bpos, apos);
swap(x0, y0);
}
cout << x0 << ' ' << y0 << ' ' << d << '\n';
x0 *= a/ apos;
y0 *= b/ bpos;
if (c % d == 0) {
fout << x0*(c/d) << ' ' << y0*(c/d) << '\n';
} else {
fout << "0 0\n";
}
}
return 0;
}