The GCD of three or more numbers equals the product of the prime factors common to all the numbers, but it can also be calculated by repeatedly taking the GCDs of pairs of numbers.

gcd(a, b, c) = gcd(a, gcd(b, c)) = gcd(gcd(a, b), c) = gcd(gcd(a, c), b)

`# GCD of more than two (or array) numbers ` `# This function implements the Euclidian ` `# algorithm to find H.C.F. of two number ` ` ` `def` `find_gcd(x, y): ` ` ` `while` `(y): ` ` ` `x, y ` `=` `y, x ` `%` `y ` ` ` ` ` `return` `x ` ` ` ` ` `l ` `=` `[` `2` `, ` `4` `, ` `6` `, ` `8` `, ` `16` `] ` ` ` `num1` `=` `l[` `0` `] ` `num2` `=` `l[` `1` `] ` `gcd` `=` `find_gcd(num1,num2) ` ` ` `for` `i ` `in` `range` `(` `2` `,` `len` `(l)): ` ` ` `gcd` `=` `find_gcd(gcd,l[i]) ` ` ` `print` `(gcd) ` ` ` `# Code contributed by Mohit Gupta_OMG ` |

*chevron_right*

*filter_none*

**Output:**

2

Please refer complete article on GCD of more than two (or array) numbers for more details!

## Recommended Posts:

- Python program to find the gcd of two numbers
- Python - Characters which Occur in More than K Strings
- Python | Program that matches a word containing 'g' followed by one or more e's using regex
- Python program to Find the Jumbo GCD subarray
- Python Program for Common Divisors of Two Numbers
- Python program to add two numbers
- Python Program to find the Quotient and Remainder of two numbers
- Python program to add two Octal numbers
- Python Program to add two hexadecimal numbers
- Python program to add two binary numbers
- Python | Indices of numbers greater than K
- Python - Find the frequency of numbers greater than each element in a list
- Python Program to remove elements that are less than K difference away in a list
- Python program to print Rows where all its Elements' frequency is greater than K
- Python program to check if the list contains three consecutive common numbers in Python
- Minimum of two numbers in Python
- Python program to find uncommon words from two Strings
- Python program to swap two elements in a list
- Python Program for Median of two sorted arrays of same size
- Python Program for Find the closest pair from two sorted arrays