Pagini recente » Cod sursa (job #2376833) | Cod sursa (job #537078) | Cod sursa (job #534345) | Cod sursa (job #534376) | Cod sursa (job #2860609)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int t;
void euclid(int a, int b, int &d, int &x, int &y){
if(b == 0){
d = a;
x = 1;
y = 1;
}
else{
int x0, y0;
euclid(b, a%b, d, x0, y0);
x = y0;
y = x0-(a/b)*y0;
}
}
int main()
{
fin >> t;
for(int i=1; i<=t; i++){
int a, b, c, d, x, y;
fin >> a >> b >> c;
euclid(a, b, d, x, y);
if(c % d != 0){
x = 0;
y = 0;
}
else{
x *= (c/d);
y *= (c/d);
}
fout << x << ' ' << y << '\n';
}
return 0;
}