Python math.gcd() Metodo
Esempio
Trova il massimo comun divisore dei due interi:
#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))
Definizione e utilizzo
Il math.gcd()
metodo restituisce il massimo comune divisore dei due interi int1 e int2 .
GCD è il massimo comun divisore che divide i numeri senza resto.
GCD è anche noto come il più alto fattore comune (HCF).
Suggerimento: gcd(0,0) restituisce 0.
Sintassi
math.gcd(int1, int2)
Valori dei parametri
Parameter | Description |
---|---|
int1 | Required. The first integer to find the GCD for |
int2 | Required. The second integer to find the GCD for |
Dettagli tecnici
Valore di ritorno: | Un int valore, che rappresenta il massimo comun divisore (MCD) per due numeri interi |
---|---|
Versione Python: | 3.5 |