Méthode Python math.gcd()
Exemple
Trouver le plus grand commun diviseur des deux entiers :
#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))
Définition et utilisation
La math.gcd()
méthode renvoie le plus grand diviseur commun des deux entiers int1 et int2 .
PGCD est le plus grand diviseur commun qui divise les nombres sans reste.
GCD est également connu comme le facteur commun le plus élevé (HCF).
Astuce : pgcd(0,0) renvoie 0.
Syntaxe
math.gcd(int1, int2)
Valeurs des paramètres
Parameter | Description |
---|---|
int1 | Required. The first integer to find the GCD for |
int2 | Required. The second integer to find the GCD for |
Détails techniques
Valeur de retour : | Une int valeur, représentant le plus grand diviseur commun (PGCD) pour deux entiers |
---|---|
Version Python : | 3.5 |