Overview
- The gcd() function of Python math maodule returns the greatest common divisor of a set of integers.
- The greatest common divisor (GCD) of a set of integers is the largest integer that divides each of them without a remainder.
Example
import math
# Find the GCD of 12, 44
number1 = 12
number2 = 44
GCD = math.gcd(number1,number2)
print("GCD of {} and {} is:{}".format(number1, number2, GCD))
# Find the GCD of 22, 121
number1 = 22
number2 = 121
GCD = math.gcd(number1,number2)
print("GCD of {} and {} is:{}".format(number1, number2, GCD))Output
GCD of 12 and 44 is:4
GCD of 22 and 121 is:11