Pagini recente » Cod sursa (job #513837) | Cod sursa (job #1105833) | Istoria paginii runda/6pb/clasament | Cod sursa (job #1704419) | Cod sursa (job #1435251)
#include <iostream>
#include <fstream>
#define INPUT_FILE "euclid3.in"
#define OUTPUT_FILE "euclid3.out"
std::fstream in(INPUT_FILE, std::fstream::in);
std::fstream out(OUTPUT_FILE, std::fstream::out);
using namespace std;
void euclid(int a, int b, int *d, int *x, int *y) {
if (b == 0) {
*d = a;
*x = 1;
*y = 0;
} else {
int x_aux, y_aux;
euclid(b, (a%b), d, &x_aux, &y_aux);
*x = y_aux;
*y = x_aux - (a/b)*y_aux;
}
}
int main(int argc, char const *argv[])
{
int numberOf;
int a, b, c;
int d, x, y;
d = x = y = 0;
in >> numberOf;
for (int i = 0; i < numberOf; i++) {
in >> a >> b >> c;
euclid(a, b, &d, &x, &y);
int q = (c/d);
if (c%d == 0) {
cout << (q*x) << " " << (q*y) << "\n";
} else {
cout << "0 0\n";
}
cout << x << " " << y << " " << d << " " << c << "\n";
}
out.close();
in.close();
return 0;
}