#K60392. Least Possible Non-Zero Element

    ID: 31076 Type: Default 1000ms 256MiB

Least Possible Non-Zero Element

Least Possible Non-Zero Element

You are given an array of positive integers. Your task is to compute the least possible non-zero element that remains after performing a series of optimal operations. It can be shown that regardless of the operations performed optimally, the answer is the greatest common divisor (gcd) of all the elements in the array.

In mathematical terms, for an array \(a_1, a_2, \ldots, a_n\), you are required to compute

[ gcd(a_1, a_2, \ldots, a_n) ]

For example:

  • For the array [10, 7, 9, 5], the answer is 1.
  • For the array [4, 4, 4, 4], the answer is 4.
  • For the array [2, 2, 3, 7, 11], the answer is 1.
  • For the array [1000000, 500000, 250000, 125000], the answer is 125000.
  • For the array [8, 12], the answer is 4.
  • For the array [6, 9, 15, 25], the answer is 1.

Implement a program that reads from standard input (stdin) and outputs the answer on standard output (stdout).

inputFormat

The input consists of two lines:

  • The first line contains a single integer \(n\) denoting the number of elements in the array.
  • The second line contains \(n\) space-separated positive integers representing the elements of the array.

outputFormat

Output a single integer which is the least possible non-zero element obtainable, which is the gcd of all the array elements.

## sample
4
10 7 9 5
1