Pagini recente » Cod sursa (job #1393632) | Cod sursa (job #133241) | Cod sursa (job #1669686) | Cod sursa (job #2407702) | Cod sursa (job #1814352)
#include <cstdio>
using namespace std;
int aee(int a, int b, int &x, int &y) /// x0, y0 - param de transef, mobili, care pot reprezenta oricand o sol, cu ajutorur carora se calculeaza x si y
{
if(!b)
{
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = aee(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main()
{
freopen("euclid3.in", "r", stdin);
freopen("euclid3.out", "w", stdout);
int t, a, b, c;
scanf("%d", &t);
while(t--)
{
scanf("%d %d %d", &a, &b, &c);
int d, x, y;
d = aee(a, b, x, y); /// d = cmmdc(a, b)
if(c % d != 0) printf("0 0\n"); /// ec nu are sol
else printf("%d %d\n", x * (c / d), y * (c / d)); /// a * x * c/d + b * y * c / d = d * c/d
}
return 0;
}