Pagini recente » Cod sursa (job #81324) | Cod sursa (job #458650) | Cod sursa (job #21180) | Cod sursa (job #3170376) | Cod sursa (job #1784868)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
void egcd(int a, int b, int *d, int *x, int *y) {
if (b == 0) {
*d = a;
*x = 1;
*y = 0;
}
else {
int x0, y0;
egcd(b, a%b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b)*y0;
}
}
int main(){
int n;
int a, b, c,d, x, y;
f >> n;
for (int i = 1; i <= n; ++i) {
f >> a >> b >> c;
egcd(a, b, &d, &x, &y);
if (c%d != 0)
g << "0 0\n";
else
g << x*(c / d) << " " << y*(c / d) << "\n";
}
return 0;
}