Pagini recente » Cod sursa (job #73509) | Cod sursa (job #2798926) | Cod sursa (job #1692635) | Cod sursa (job #2392786) | Cod sursa (job #1810835)
#include <iostream>
#include <fstream>
using namespace std;
void solve(int a, int b, int *d, int *x, int *y){
if (b != 0){
int x0, y0;
solve(b, a%b, d, &x0, &y0);
*x = y0;
*y = x0 - (a/b)*y0;
cout << *x << " " << *y << "\n";
} else {
*d = a;
*x = 1;
*y = 0;
cout << *x << " " << *y << "\n";
}
}
int main(){
ifstream in;
ofstream out;
in.open("euclid3.in");
out.open("euclid3.out");
int t,a,b,c,d;
in >> t;
int x,y;
for (int i=0; i<t; i++){
x = 0;
y = 0;
in >> a >> b >> c;
solve(a,b,&d,&x,&y);
if (c%d == 0){
out << x*(c/d) << " " << y*(c/d) << "\n";
} else {
out << 0 << " " << 0 << "\n";
}
}
return 0;
}