函数 xgcd #
计算两个值的扩展最大公约数。请参阅 https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm。
Syntax #
math.xgcd(a, b)
Parameters #
| Parameter | Type | Description |
|---|---|---|
a |
number | BigNumber | 一个整数 |
b |
number | BigNumber | 一个整数 |
Returns #
| Type | Description |
|---|---|
| Array | 返回一个包含 3 个整数的数组 [div, m, n],其中 div = gcd(a, b) 且 a*m + b*n = div |
Throws #
Type | Description —- | ———–
Examples #
math.xgcd(8, 12) // returns [4, -1, 1]
math.gcd(8, 12) // returns 4
math.xgcd(36163, 21199) // returns [1247, -7, 12]