#C2772. Greatest Common Divisor of an Array

    ID: 46125 Type: Default 1000ms 256MiB

Greatest Common Divisor of an Array

Greatest Common Divisor of an Array

Given an array of positive integers, your task is to compute the Greatest Common Divisor (GCD) of the array. The GCD of a set of numbers is the largest positive integer that divides each of the integers without leaving a remainder. Mathematically, you are asked to calculate \(\gcd(a_1, a_2, \ldots, a_n)\).

For example, if the array is [2, 4, 6], the GCD is 2.

inputFormat

The input consists of two lines:

  1. The first line contains a single integer \(n\) (\(1 \le n \le 10^5\)), representing the number of elements in the array.
  2. The second line contains \(n\) space-separated positive integers (each at most \(10^9\)).

outputFormat

Output a single integer: the greatest common divisor of the given array of integers.

## sample
3
2 4 6
2