#K39552. Reducing Array Maximum via GCD Operations
Reducing Array Maximum via GCD Operations
Reducing Array Maximum via GCD Operations
You are given an integer array arr
of size \(n\). You can perform an arbitrary number of operations. In each operation, you may choose any two elements of the array and replace them with their greatest common divisor (i.e., \(\gcd(x, y)\)). Your task is to determine the minimum possible value of the maximum element in the array after performing any sequence of such operations.
Key Observation: No matter how many operations you perform, the final answer is equal to the \(\gcd\) of all the elements in the array. That is, if \(g = \gcd(arr_1, arr_2, \ldots, arr_n)\), then the minimum possible maximum value is \(g\).
Input/Output: The input is read from standard input and the output should be printed to standard output.
Example:
Input: 6 8 4 12 16 2 10</p>Output: 2
inputFormat
The first line of input contains a single integer \(n\) \( (1 \le n \le 10^5) \) representing the number of elements in the array.
The second line contains \(n\) space-separated integers \(a_1, a_2, \ldots, a_n\) \( (1 \le a_i \le 10^9) \) representing the elements of the array.
Input is provided via standard input (stdin).
outputFormat
Print a single integer: the minimized maximum element of the array after performing the operations, which is the \(\gcd\) of all elements in the array.
Output should be written to standard output (stdout).
## sample1
5
5