Pagini recente » Rating sandica cosmina (cozmina) | Cod sursa (job #2350277) | Cod sursa (job #1685608) | Cod sursa (job #2953777) | Cod sursa (job #327157)
Cod sursa(job #327157)
#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", x * c / cmmdc, y * c / cmmdc);
}
}
fclose(stdin);
fclose(stdout);
return 0;
}