#K79287. Greatest Common Divisor of a List
Greatest Common Divisor of a List
Greatest Common Divisor of a List
Given a list of integers, compute their greatest common divisor (gcd). The gcd of two integers \(a\) and \(b\) is defined using Euclid's algorithm as follows:
\[ \gcd(a, b) = \gcd(b, a \mod b)\]
with the base case \(\gcd(a, 0) = a\). For a list of numbers \(a_1, a_2, \dots, a_n\), the overall gcd can be computed iteratively as:
\[ \gcd(a_1, a_2, \dots, a_n) = \gcd(\gcd(a_1, a_2), a_3, \dots, a_n)\]Read the input from stdin and output the result to stdout.
inputFormat
Input Format: The first line contains an integer (n), which represents the number of integers in the list. The second line contains (n) space-separated integers.
outputFormat
Output Format: Output a single integer, the greatest common divisor of the list.## sample
3
6 9 15
3