Pagini recente » Rating Tudor Roman (romantudorel) | Cod sursa (job #2222116) | Cod sursa (job #1966396) | Cod sursa (job #1203282) | Cod sursa (job #327158)
Cod sursa(job #327158)
#include <algorithm>
#include <stdio.h>
using namespace std;
int t;
inline int gcd(int a, int b)
{
if (!b)
return a;
return gcd(b, a % b);
}
inline void euclidExtins(int a, int b, int &x, int &y)
{
if (!b)
{
x = 1;
y = 0;
return;
}
euclidExtins(b, a % b, x, y);
int xp = x;
x = y;
y = xp - (a / b) * y;
}
int main()
{
freopen("euclid3.in", "r", stdin);
freopen("euclid3.out", "w", stdout);
for (scanf("%d", &t); t; t--)
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
int cmmdc = gcd(a, b);
if (c % cmmdc)
printf("0 0\n");
else
{
int x, y;
euclidExtins(a, b, x, y);
printf("%d %d\n", c / cmmdc * x, c / cmmdc * y);
}
}
fclose(stdin);
fclose(stdout);
return 0;
}