#K39592. Minimum Possible Sum after GCD Operations

    ID: 26454 Type: Default 1000ms 256MiB

Minimum Possible Sum after GCD Operations

Minimum Possible Sum after GCD Operations

You are given an array of n positive integers \(a_1, a_2, \ldots, a_n\). You can perform a series of operations on this array (in theory, any number of times) such that the minimal possible sum of the array after all operations is achieved. It can be proved that the minimal sum obtainable is

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

Your task is to compute and output this minimum possible sum.

inputFormat

The input is given from standard input and consists of two lines:

  • The first line contains a single integer \(n\) (\(1 \le n \le 10^5\)), the number of elements in the array.
  • The second line contains \(n\) space-separated positive integers \(a_1, a_2, \ldots, a_n\) (each \(a_i\) is at most \(10^9\)).

outputFormat

Output a single integer representing the minimum possible sum of the array, which is \(n \times \gcd(a_1, a_2, \ldots, a_n)\).

## sample
3
4 8 12
12

</p>