Método Python math.gcd()
Exemplo
Encontre o máximo divisor comum dos dois inteiros:
#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))
Definição e uso
O math.gcd()
método retorna o máximo divisor comum dos dois inteiros int1 e int2 .
GCD é o maior divisor comum que divide os números sem deixar resto.
O GCD também é conhecido como o fator comum mais alto (HCF).
Dica: gcd(0,0) retorna 0.
Sintaxe
math.gcd(int1, int2)
Valores de parâmetro
Parameter | Description |
---|---|
int1 | Required. The first integer to find the GCD for |
int2 | Required. The second integer to find the GCD for |
Detalhes técnicos
Valor de retorno: | Um int valor, representando o máximo divisor comum (GCD) para dois inteiros |
---|---|
Versão do Python: | 3,5 |