Codeforces 389A (Greatest common divisor)

Source: Internet
Author: User
Tags greatest common divisor

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.