We know that by means of extended euclidean algorithm x
and y
can be calculated from ax + by = gcd(a, b)
. The formula is:
x = prev_y;
y = prev_x - (a/b) * x;
and the code is:
int gcd(int a, int b, int& x, int& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int x1, y1;
int d = gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
But in case of multiple integers, for instance, ax + by + cz = gcd(a, b, c)
, what will be the approach and code?