#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll egcd(ll a, ll b, ll &x, ll &y)
{
if(a == 0)
{
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll d = egcd(b%a, a, x1, y1);
x = y1 - (b/a) * x1;
y = x1;
return d;
}
int main()
{
ll x, y, a, b;
while(cin >> a >> b)
{
ll n = egcd(a, b, x, y);
if(a == b && y < x)
swap(x, y);
cout << x << " " << y << " " << n << endl;
x = y = 0;
}
return 0;
}
#define ll long long int
using namespace std;
ll egcd(ll a, ll b, ll &x, ll &y)
{
if(a == 0)
{
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll d = egcd(b%a, a, x1, y1);
x = y1 - (b/a) * x1;
y = x1;
return d;
}
int main()
{
ll x, y, a, b;
while(cin >> a >> b)
{
ll n = egcd(a, b, x, y);
if(a == b && y < x)
swap(x, y);
cout << x << " " << y << " " << n << endl;
x = y = 0;
}
return 0;
}
Comments
Post a Comment