Pagini recente » Cod sursa (job #2903462) | Cod sursa (job #2276293) | Cod sursa (job #1204986) | Cod sursa (job #955619) | Cod sursa (job #2982934)
#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 x0, y0, x1, y1;
x0 = 1;
x1 = 0;
y0 = 0;
y1 = 1;
while(b)
{
int r = a % b;
int q = a / b;
x = x0 - q * x1;
y = y0 - q * y1;
a = b;
b = r;
x0 = x1;
x1 = x;
y0 = y1;
y1 = y;
}
x = x0;
y = y0;
return a;
}
int main()
{
int t, a, b, c;
fin >> t;
for(int i = 1; i <= t; i++)
{
fin >> a >> b >> c;
int x, y;
int d = euclid(a, b, x, y);
if(c % d == 0)
fout << x * (c / d) << ' ' << y * (c / d) << '\n';
else
fout << 0 << ' ' << 0 << '\n';
}
return 0;
}