CF228A题Fox and Number Game

来源:互联网 发布:telnet默认端口 编辑:程序博客网 时间:2024/05/09 08:53

这个题虽然题目不长,英语也不难,但是还是看了好长时间才明白什么意思。。这个题利用了最大公约数来做的

Fox Ciel is playing a game with numbers now.

Ciel has n positive integers: x1x2, ..., xn. She can do the following operation as many times as needed: select two different indexes iand 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: x1x2, ..., xn (1 ≤ xi ≤ 100).

Output

Output a single integer — the required minimal sum.

Sample test(s)
input
21 2
output
2
input
32 4 6
output
6
input
212 18
output
12
input
545 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 - x2x2 = x2 - x1.


#include <stdio.h>#include <string.h>int main(){    int n, i, a[102], j, x, y, z = 101;    scanf("%d",&n);    for(i=0;i<n;i++)        {scanf("%d",&a[i]);        if(z>a[i])            z=a[i];        }    for(j=z; j >= 0; j--)    {        x=0;        for(i=0;i<n;i++)        {            if(a[i]%j!=0)            {                x=1;                break;            }        }        if(x==0)        {y=j;break;}    }    printf("%d\n",y*n);    return 0;}


0 0