Extended Euclidean Algorithm | ax + by + cz = gcd(a, b, c)

Revision en1, by 1507002, 2020-06-21 21:41:46

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?

Tags #extended_euclidean, #gcd, #euclidean, #algorithms

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English 1507002 2020-06-21 21:41:46 650 Initial revision (published)