xgcd.md (916B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 2 3 # Function xgcd 4 5 Calculate the extended greatest common divisor for two values. 6 See https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm. 7 8 9 ## Syntax 10 11 ```js 12 math.xgcd(a, b) 13 ``` 14 15 ### Parameters 16 17 Parameter | Type | Description 18 --------- | ---- | ----------- 19 `a` | number | BigNumber | An integer number 20 `b` | number | BigNumber | An integer number 21 22 ### Returns 23 24 Type | Description 25 ---- | ----------- 26 Array | Returns an array containing 3 integers `[div, m, n]` where `div = gcd(a, b)` and `a*m + b*n = div` 27 28 29 ### Throws 30 31 Type | Description 32 ---- | ----------- 33 34 35 ## Examples 36 37 ```js 38 math.xgcd(8, 12) // returns [4, -1, 1] 39 math.gcd(8, 12) // returns 4 40 math.xgcd(36163, 21199) // returns [1247, -7, 12] 41 ``` 42 43 44 ## See also 45 46 [gcd](gcd.md), 47 [lcm](lcm.md)