CKTIS / Python
math.gcd
Computes the greatest common divisor of the supplied integers.
Version: Python 3.14; repository image, production runtime not attested
Syntax
math.gcd(*integers)Computes the greatest common divisor of the supplied integers.
Signs do not change the nonnegative result; a sequence containing only zeroes gives zero.
Six divides all three inputs and no larger positive integer does. Any number of integer arguments is accepted. Signs do not affect divisibility. With just zeroes or with no arguments the function returns zero.
import math
assert math.gcd(-12, 18, 30) == 6 and math.gcd() == 0
assert math.gcd(0, -12) == 12
Examples
import math
print(math.gcd(-12, 18, 30))
print(math.gcd(0, 0))
Result
6 0
Six divides all three inputs and no larger positive integer does. Any number of integer arguments is accepted. Signs do not affect divisibility. With just zeroes or with no arguments the function returns zero.