Module: (Python) Practicum 4. Euclid's Algorithm


Problem

2/6

gcd n numbers

Theory Click to read/hide

In Python, the math module contains a number of mathematical operations that can be performed fairly quickly. The built-in function math.gcd(a, b), which calculates the GCD of any two integersnumbers. Can be used from version 3.5.

Problem

Write a function to find the greatest common divisor of two numbers using Euclid's algorithm and use it to write a function solve(A) that determines the gcd of already n non-negative numbers, where A is an array of numbers. 

You don't need to input or output anything, just implement these functions.

 

Examples
# Input Output
1 3
24 8 20
4
2 4
0 2 4 8
2