Pagini recente » Cod sursa (job #222133) | Cod sursa (job #2138552) | Cod sursa (job #2614919) | Cod sursa (job #503658) | Cod sursa (job #1435250)
#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 = x_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 cat = c/d;
if (c%d == 0) {
out << x*cat << " " << y*cat << "\n";
} else {
out << "0 0" << "\n";
}
}
out.close();
in.close();
return 0;
}