Fox and number Game
Time Limit: 1000MS |
|
Memory Limit: 262144KB |
|
64bit IO Format: %i64d &%i64u |
Submit Status
Description
Fox Ciel is playing a game with numbers now.
Ciel hasNPositive integers:x1, x 2, ..., x n . She can do the following operation as many times as Needed:select II different Indexes I and J such That x i > x J hold, and then apply Assignment x i = x i - x J . The goal is to do the sum of all numbers as small as possible.
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, ..., x n (1≤ xi ≤100).
Output
Output a single integer-the required minimal sum.
Sample Input
Input
2
1 2
Output
2
Input
3
2 4 6
Output
6
Input
2
12 18
Output
12
Input
5
45 12 27) 30 18
Output
15
Hint
In the first example the optimal-on-the-assignment: x 2 = x2- x 1.
In the second example the optimal sequence of operations are: x3 = x3- x 2, x2 = x2- x1.
Source
Codeforces Round #228 (Div. 2) The problem: to convert the title, is to find the N number of greatest common divisor multiplied by N.
#include <iostream>#include<stdlib.h>#include<stdio.h>#include<algorithm>#include<string.h>#include<math.h>using namespaceStd;typedefLong Longll;ll gcd (ll a,ll b) {if(b==0)returnA; Else returnGCD (b,a%b);}intMain () {inti,n,ans,a[ the]; while(cin>>N) {cin>>a[0]; Ans=a[0]; for(i=1; i<n;i++) {cin>>A[i]; Ans=gcd (Ans,a[i]); } cout<<ans*n<<Endl; } return 0;}
Codeforces 389A (Greatest common divisor)