Pagini recente » Cod sursa (job #1255899) | Cod sursa (job #1069485) | Cod sursa (job #743166) | Cod sursa (job #2638470) | Cod sursa (job #2875880)
#include <bits/stdc++.h>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
int gcd_facut_in_casa(int a, int b)
{
int c;
while(b)
{
c = b;
b = a % b;
a = c;
}
return a;
}
void euclid_extins(int a, int b, int *d, int *x, int *y)
{
if(b == 0)
{
*d = a;
*x = 1;
*y = 0;
}
else
{
int x0, y0;
euclid_extins(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main()
{
int T, a, b, c, d;
in >> T;
while(T--)
{
in >> a >> b >> c;
//d = __gcd(a,b);
d = gcd_facut_in_casa(a,b);
//out << d << '\n';
if(c % d)
{
out << 0 << " " << 0 << '\n';
}
else
{
int e, x, y;
euclid_extins(a, b, &e, &x, &y);
//out << a << " " << b << " " << e << " " <<x << " " << y << '\n';
out << x * c / d << " " << y * c / d << '\n';
}
}
return 0;
}