#include<iostream>
#include<cstdio>
using namespace std;
int a,b,x,y;
int gcd(int a,int b)
{
if(a%b==0)
return b;
return gcd(b,a%b);
}
int ex_gcd(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1;y=0;
return a;
}
int r=ex_gcd(b,a%b,x,y);
int t=x;x=y;y=t-a*y/b;
return r;
}
int main()
{
cin>>a>>b;
cout<<gcd(a,b)<<endl;
cout<<ex_gcd(a,b,x,y)<<endl;
cout<<x;//x为a关于%b的乘法逆元
return 0;
}