Code: Select all

```
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int gcd (int p,int q) //gcd function running fine
{
int t;
if (p==0 || q==0)
{if (p==0)
return q;
else
return p;
}
if (q>p)
{t=p;
p=q;
q=t;
}
while (q>0)
{
t=q;
q=p%q;
p=t;
}
return p;
}
int main()
{
int a,b;
while (cin>>a>>b)
{
int d,x,y=1,m,n;
bool flag=true,flag1,f=false;
d=gcd(a,b);
if(a!=0 && b!=0)
flag1=true;
if(a==0 && b==0)
f=true;
if(f!=true){
while (flag==true)
{if(a!=0 && b!=0)
{
if (((d-b*y)%a)==0)
{x=((d-b*y)/a);
flag=false;
}
y++;
}
else
{x=0;
y=2;
flag=false;
}
}
int x1,y1=-1;
while (flag1==true)
{
if (((d-b*y1)%a)==0)
{x1=((d-b*y1)/a);
flag1=false;
}
y1--;
}
if(abs(x)+abs(y)<=abs(x1)+abs(y1))
cout<<x<<" "<<y-1<<" "<<d<<endl;
else
cout<<x1<<" "<<y1+1<<" "<<d<<endl;
}
else
cout<<"0"<<" "<<"0"<<" "<<"0"<<endl;
}
return 0;
}
[b][/b][b][/b]
```