Skip to content

Instantly share code, notes, and snippets.

@Sicalxy
Created August 3, 2019 14:11
Show Gist options
  • Save Sicalxy/7ca35eb7ea9f6bd81e47196ce7944502 to your computer and use it in GitHub Desktop.
Save Sicalxy/7ca35eb7ea9f6bd81e47196ce7944502 to your computer and use it in GitHub Desktop.
Extended Euclidean Algorithm 扩展欧几里得算法
int gcdEx(int a, int b, int *x, int *y)
{
if(0 == b)
{
*x = 1;
*y = 0;
return a;
}
else
{
int r = gcdEx(b, a % b, x, y);
int t = *x;
*x = *y;
*y = t - a / b * (*y);
return r;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment