Método Python math.gcd()
Ejemplo
Encuentra el máximo común divisor de los dos enteros:
#Import math Library
import math
#find the the greatest
common divisor of the two integers
print (math.gcd(3, 6))
print (math.gcd(6,
12))
print (math.gcd(12, 36))
print (math.gcd(-12, -36))
print (math.gcd(5,
12))
print (math.gcd(10, 0))
print (math.gcd(0, 34))
print (math.gcd(0,
0))
Definición y uso
El math.gcd()
método devuelve el máximo común divisor de los dos enteros int1 e int2 .
MCD es el máximo común divisor que divide los números sin resto.
GCD también se conoce como el factor común más alto (HCF).
Consejo: gcd(0,0) devuelve 0.
Sintaxis
math.gcd(int1, int2)
Valores paramétricos
Parameter | Description |
---|---|
int1 | Required. The first integer to find the GCD for |
int2 | Required. The second integer to find the GCD for |
Detalles técnicos
Valor devuelto: | Un int valor, que representa el máximo común divisor (MCD) de dos enteros |
---|---|
Versión de Python: | 3.5 |