MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / ExtendedRecursive

Function ExtendedRecursive

math/gcd/extendedgcd.go:9–17  ·  view source on GitHub ↗

ExtendedRecursive finds and returns gcd(a, b), x, y satisfying a*x + b*y = gcd(a, b).

(a, b int64)

Source from the content-addressed store, hash-verified

7
8// ExtendedRecursive finds and returns gcd(a, b), x, y satisfying a*x + b*y = gcd(a, b).
9func ExtendedRecursive(a, b int64) (int64, int64, int64) {
10 if b > 0 {
11 d, y, x := ExtendedRecursive(b, a%b)
12 y -= (a / b) * x
13 return d, x, y
14 }
15
16 return a, 1, 0
17}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected