Pagini recente » Cod sursa (job #493682) | Cod sursa (job #1282222) | Cod sursa (job #2559488) | Cod sursa (job #2156026) | Cod sursa (job #2825211)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int euclid(int a, int b, int &x, int &y) {
if(b == 0) {
x = 1;
y = 0;
return a;
} else {
int x0, y0;
int d = euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
}
inline int gcd( int A, int B, int &X, int &Y )
{
if (B == 0)
{
X = 1;
Y = 0;
return A;
}
int X0, Y0, D;
D = gcd( B, A % B, X0, Y0 );
X = Y0;
Y = X0 - (A / B) * Y0;
return D;
}
int t, a, b, c;
int main() {
fin >> t;
while(t > 0) {
fin >> a >> b >> c;
int x, y;
int d = gcd(a, b, x, y);
if(c % d == 0) {
fout << (x * (c / d) ) << " " << (y * (c / d) ) << "\n";
} else {
fout << "0 0\n";
}
t--;
}
return 0;
}