Pagini recente » Cod sursa (job #2305711) | Cod sursa (job #2221582)
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int euclid3(int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
else
{
int x1, y1;
int d = euclid3(b, a % b, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
return d;
}
}
int main()
{
freopen("euclid3.in", "r", stdin);
freopen("euclid3.out", "w", stdout);
int t;
scanf("%d", &t);
for(int test = 0; test < t; ++test)
{
int a, b, c;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
int x, y;
int d = euclid3(a, b, x, y);
if(c % d != 0)
{
printf("0 0\n");
continue;
}
else
{
printf("%d %d\n", x * (c / d), y * (c / d));
}
}
return 0;
}