Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / Python

math.gcd

Devuelve el máximo común divisor no negativo de cualquier cantidad de enteros.

Versión: Python 3.14; repository image, production runtime not attested

Sintaxis

math.gcd(*integers)

Devuelve el máximo común divisor no negativo de cualquier cantidad de enteros.

El mayor entero que divide −12, 18 y 30 es 6. Los signos no influyen.

Solo ceros o ningún argumento dan 0.

import math
assert math.gcd(-12, 18, 30) == 6 and math.gcd() == 0
assert math.gcd(0, -12) == 12

Ejemplos

import math
print(math.gcd(-12, 18, 30))
print(math.gcd(0, 0))

Resultado

6
0

Solo ceros o ningún argumento dan 0.

Fuentes