Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Extended Euclid Algorithm Recursive Solution

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;
}
Source by cp-algorithms.com #
 
PREVIOUS NEXT
Tagged: #Extended #Euclid #Algorithm #Recursive #Solution
ADD COMMENT
Topic
Name
2+2 =