Pagini recente » Cod sursa (job #2934135) | Cod sursa (job #390337) | Cod sursa (job #2284317) | Cod sursa (job #347683) | Cod sursa (job #2470781)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int euclext(int a, int b, int c, int &x, int &y)
{
int q[50], x0, y0, r, pos = 0;
while(b)
{
q[++pos] = a / b;
r = a % b;
a = b;
b = r;
}
if(c % a) {x=y=0;return 0;}
x0 = c / a;
y0 = 0;
while(pos)
{
x = y0;
y = x0 - q[pos--] * y0;
x0 = x;
y0 = y;
}
return 1;
}
int main()
{
int t;
fin >> t;
for(int i = 0; i < t; i++)
{
int a, b, c, x, y;
fin >> a >> b >> c;
euclext(a, b, c, x, y);
fout << x << " " << y << "\n";
}
return 0;
}