Python math.gcd() Method
Example
Find the highest possible number that can divide two numbers:
#Import math Library
import math
#find the highest number that can divide two
numbers
print (math.gcd(26, 12))
print (math.gcd(12, 6))
print (math.gcd(10, 0))
print
(math.gcd(0, 34))
print (math.gcd(0, 0))
Try it Yourself »
Definition and Usage
The math.gcd()
method returns the highest value that can divide two
integers. This is know as the greatest common divisor (GCD), or the highest common factor (HCF).
Tip: If the two values are zero (gcd(0,0)), it returns 0 as result.
Syntax
math.gcd(a, b)
Parameter Values
Parameter | Description |
---|---|
a | Required. The first integer to find the GCD for |
b | Required. The second integer to find the GCD for |
Technical Details
Return Value: | An int value, representing the greatest common divisor (GCD) for two integers |
---|---|
Python Version: | 3.5 |