Euclid Extended

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
236 B
3
Indexable
Never
int gcd_extend(int a, int b, int* x, int* y) {
  if(a == 0) {
    *x = 0;
    *y = 1;
    
    return b;
  }

  int gcd = gcd_extend(b % a, a, x, y);
  int temp = *x;
  *x = *y - (b/a)*(*x);
  *y = temp;
  
  return gcd;
}