~cpp
// no10104 - Euclid Problem
#include <iostream>
#include <cmath>
using namespace std;
int gcd(int p, int q, int & x, int & y);
int main()
{
int a, b;
int x, y;
int g; // gcd
while (cin >> a >> b)
{
g = gcd(a, b, x, y);
cout << x << " " << y << " " << g << endl;
}
return 0;
}
int gcd(int p, int q, int & x, int & y)
{
int x1, y1; // 계
int g; // gcd
if (p < q) return (gcd(q, p, y, x));
if (q == 0)
{
x = 1;
y = 0;
return p;
}
g = gcd(q, p%q, x1, y1);
x = y1;
y = (x1 - floor(p/q) * y1);
return g;
}