函数 gcd #

计算两个或多个值或数组的最大公约数。

对于矩阵,该函数逐元素求值。

Syntax #

math.gcd(a, b)
math.gcd(a, b, c, ...)

Parameters #

Parameter Type Description
args … number | BigNumber | Fraction | Array | Matrix 两个或多个整数

Returns #

Type Description
number | BigNumber | Fraction | Array | Matrix 最大公约数

Throws #

Type | Description —- | ———–

Examples #

math.gcd(8, 12)              // returns 4
math.gcd(-4, 6)              // returns 2
math.gcd(25, 15, -10)        // returns 5

math.gcd([8, -4], [12, 6])   // returns [4, 2]

另请参阅 #

lcm, xgcd

Fork me on GitHub