Function Xgcd(a, b)
Dim result(3)
x = 0: y = 1: result(1) = 1: result(2) = 0: result(3) = a
Do While b > 0
temp = b
quotient = Int(result(3) / b)
b = result(3) Mod b
result(3) = temp
temp = x
x = result(1) - quotient * x
result(1) = temp
temp = y
y = result(2) - quotient * y
result(2) = temp
Loop
Xgcd = result
End Function
'Example
Sub getXgcd()
Dim xg()
xg() = Xgcd(838041641, 198491329)
Debug.Print "ax + by = gcd(838041641, 198491329)" & Chr(13) & "x is " & xg(1) & ", y is " & xg(2) & " and a is " & xg(3)
End Sub