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

Function ExtendedIterative

math/gcd/extendedgcditerative.go:4–13  ·  view source on GitHub ↗

ExtendedIterative 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

2
3// ExtendedIterative finds and returns gcd(a, b), x, y satisfying a*x + b*y = gcd(a, b).
4func ExtendedIterative(a, b int64) (int64, int64, int64) {
5 var u, y, v, x int64 = 1, 1, 0, 0
6 for a > 0 {
7 var q int64 = b / a
8 x, u = u, x-q*u
9 y, v = v, y-q*v
10 b, a = a, b-q*a
11 }
12 return b, x, y
13}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected