Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Created March 16, 2015 18:20
Show Gist options
  • Save shohan4556/e47153446c58637240d2 to your computer and use it in GitHub Desktop.
Save shohan4556/e47153446c58637240d2 to your computer and use it in GitHub Desktop.
UVA -- 10104 solution
#include<stdio.h>
int extends_euclid(int a,int b,int &x,int &y);
int main()
{
int a,b,x,y;
int d;
while(scanf("%d %d",&a,&b)==2){
d=extends_euclid(a,b,x,y);
if (a == b) {
x = 0;
y = 1;
}
printf("%d %d %d\n",x,y,d);
}
return 0;
}
int extends_euclid(int a,int b,int &x,int &y)
{
int x1,y1,d;
if(a==0){
x=0;
y=1;
return b;
}
d=extends_euclid(b%a,a,x1,y1);
x=y1-(b/a)*x1;
y=x1;
return d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment