Pagini recente » Cod sursa (job #3271655) | IAP #6: Arhiva educationala | Cod sursa (job #1950659) | Cod sursa (job #228587) | Cod sursa (job #3268407)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int T,a,b,c,x,y;
int xGCD(int a, int b, int &x, int &y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
int x1, y1, gcd = xGCD(b, a % b, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
return gcd;
}
int main()
{
fin>>T;
while(T--)
{
fin>>a>>b>>c;
if(a<b) swap(a,b);
int d = xGCD(a,b,x,y);
if(c%d!=0)fout<<0<<" "<<0<<'\n';
else fout<<x*(c/d)<<" "<<y*(c/d)<<"\n";
}
return 0;
}