Pagini recente » Cod sursa (job #2935839) | Cod sursa (job #1928397) | Cod sursa (job #938621) | Cod sursa (job #2338705) | Cod sursa (job #2222319)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int cmmdc(int a, int b) {
if (b == 0)
return a;
return cmmdc(b, a % b);
}
void solve(int a, int b, int *x, int *y, int *d) {
if (b == 0) {
*d = a;
*x = 1;
*y = 0;
} else {
int x0, y0;
solve(b, a % b, &x0, &y0, d);
*y = x0 - (a / b) * y0;
*x = y0;
}
}
int main() {
int tests;
int first, second, third, d, x, y;
ifstream input("euclid3.in");
ofstream output("euclid3.out");
input >> tests;
for (int i = 0; i < tests; i++) {
input >> first >> second >> third;
x = 0;
y = 1;
d = cmmdc(first, second);
solve(first, second, &x, &y, &d);
if (third % d != 0) {
output << "0 0\n";
continue;
}
output << x * third / d << " " << y * third / d << endl;
}
input.close();
output.close();
return 0;
}