您的位置:首页 > 其它

Codeforces Round #228 (Div. 2), problem: (A) Fox and Number Game

2015-01-07 21:21 441 查看
Codeforces Round #228 (Div. 2), problem: (A) Fox and Number Game,题目如下:

A. Fox and Number Game

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Fox Ciel is playing a game with numbers now.

Ciel has n positive integers: x1, x2,
..., xn. She
can do the following operation as many times as needed: select two different indexes i and j such
that xi > xj hold,
and then apply assignment xi = xi - xj.
The goal is to make the sum of all numbers as small as possible.

Please help Ciel to find this minimal sum.

Input

The first line contains an integer n (2 ≤ n ≤ 100).
Then the second line contains n integers: x1, x2,
..., xn (1 ≤ xi ≤ 100).

Output

Output a single integer — the required minimal sum.

Sample test(s)

input
2
1 2


output
2


input
3
2 4 6


output
6


input
212 18


output
12


input
5
45 12 27 30 18


output
15


Note

In the first example the optimal way is to do the assignment: x2 = x2 - x1.

In the second example the optimal sequence of operations is: x3 = x3 - x2, x2 = x2 - x1

意思很简单,给出n个数,执行如下操作若干次:从中任取两个数,满足,然后赋值,直到所有数的和最小。

根据题目,得出如下思路,将给出的n个数从小到大排序,为了让操作次数尽可能少,让第n个减去第n-1个,再将得

出的新数组排序,重复执行上述操作。可发现,当所有数都相等时,操作结束,此时的和最小。

题目很简单,但是演算的时候可以发现,这是在求n个数的最大公约数,所以特别将该题记录下来。代码如下:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: