Pagini recente » Cod sursa (job #164358) | Cod sursa (job #2322119) | Cod sursa (job #366793) | Cod sursa (job #2545195) | Cod sursa (job #3237028)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int euclid(int a , int b , int &x ,int &y);
int main()
{
int a, b, x, y, i, n, d, c;
fin >> n;
for(i = 0; i < n; i++)
{
fin >> a >> b >> c;
d = euclid(a, b, x, y);
if(c % d)
fout << 0 << ' ' << 0 << '\n';
else
fout << x * (c / d) << ' ' << y * (c/d) << '\n';
}
return 0;
}
int euclid(int a , int b , int &x ,int & y)
{
if(b == 0)
{
x = 1, y = 0;
return a;
}
else
{
int x1 , y1;
int d = euclid(b , a % b , x1 , y1);
x = y1;
y = x1 - a / b * y1;
return d;
}
}