Python math.gcd() Method
Python math.gcd() The method returns the greatest common divisor of the given integer arguments.
gcd(0,0) returns 0.
Python version: 3.5
Changed in version 3.9: support for an arbitrary number of arguments was added; earlier versions supported only two arguments.
Syntax
The syntax of the math.gcd() method is as follows:
math.gcd(*integers)
Parameter Description:
- *integers -- required, a number. If x is not a number, a TypeError is returned.
Return Value
Returns an integer int representing the greatest common divisor (GCD) of two or more integers.
Example
The following example returns the greatest common divisor of numbers:
Example
Import the math package
import
math
Output the greatest common divisor
(
math
.
gcd
(
3
,
6
)
)
(
math
.
gcd
(
6
,
12
)
)
(
math
.
gcd
(
12
,
36
)
)
(
math
.
gcd
(
12
,
36
)
)
(
math
.
gcd
(
5
,
12
)
)
(
math
.
gcd
(
10
,
0
)
)
(
math
.
gcd
(
0
,
34
)
)
(
math
.
gcd
(
0
,
0
)
)
Output result:
3
6
12
12
1
10
34
0
Python math Module