
int GCD(int X,int Y)
/* input two integers X,Y; return their greatest common divisor */
{
 int R;

 if (X<0) X=-X; if (Y<0) Y=-Y;
 if (X>Y) {R=X; X=Y; Y=R;}
 R=-1;
 while (R)
  {
   R=Y%X; /* Q=Y/X; printf("X=%d  Y=%d  Q=%d  R=%d\n",X,Y,Q,R); getchar(); */
   Y=X; X=R;
  }
 return Y;
}
