Python Armstrong NumberPython Average of N NumbersPython Biggest of Three NumbersPython Common DivisorsPython Composite NumberPython Condense a NumberPython Even NumberPython Factorial of a NumberPython Fibonacci SeriesPython GCDPython LCMPython Leap YearPython Multiplication TablePython Number CombinationPython Odd NumberPython Palindrome NumberPython Perfect NumberPython Prime FactorPython Prime NumberPython Sum of DigitsPython Swapping Two Numbers

Python Array ProgramsPython Converter ProgramsPython Star Patterns ProgramPython Number Patterns ProgramPython Alphabet Patterns ProgramLast Updated:

A largest number that exactly divides two or more integers.

In general, **Greatest Common Divisor** (GCD) is otherwise called as **Greatest Common Factor** (GCF) or **Highest Common Factor** (HCF)

**Tips**: It is recommended to use our online GCD calculator for better understanding.

The following table provides few examples of GCD of the given numbers.

Numbers | GCD |
---|---|

4, 10 | 2 |

6, 5 | 1 |

15, 30 , 45 | 15 |

In the following example, we will find the GCD of the given two numbers (45, 90).

Python Compiler

num1 = 45
num2 = 90
gcd = 1
min = (num1 < num2) and num1 or num2;
for i in range(1, min+1):
if((num1 % i == 0) and (num2 % i == 0)):
gcd = i
print("GCD of %d and %d: %d" % (num1, num2, gcd))

In the following example, we will find the GCD of any two given numbers.

Python Compiler

num1 = int(input("Enter (int) num1 = "))
num2 = int(input("Enter (int) num1 = "))
gcd = 1
min = (num1 < num2) and num1 or num2;
for i in range(1, min+1):
if((num1 % i == 0) and (num2 % i == 0)):
gcd = i
print("\nGCD of %d and %d: %d" % (num1, num2, gcd))