Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit Status

Description

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 i and jsuch 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 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 way is to do the assignment: x2 = x2 - x1.

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

Source

题解:将题目转化一下,就是求n个数的最大公约数再乘以n。
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
if (b==) return a;
else return gcd(b,a%b);
}
int main()
{
int i,n,ans,a[];
while (cin>>n)
{
cin>>a[];
ans=a[];
for (i=;i<n;i++)
{
cin>>a[i];
ans=gcd(ans,a[i]);
}
cout<<ans*n<<endl;
}
return ;
}

Codeforces 389A (最大公约数)的更多相关文章

  1. Codeforces 660A. Co-prime Array 最大公约数

    A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. CodeForces 346A Alice and Bob (数学最大公约数)

    题意:有一堆数,然后有两个人轮流从中取出两个数,这两个数的差的绝对值不在这个集合,然后把这个数放进这个集合,如果哪个人不能拿了,就是输了,问你谁赢. 析:当时连题意都没看好,以为拿出两个数,就不放回了 ...

  3. Codeforces Round #275 (Div. 2) A. Counterexample【数论/最大公约数】

    A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. Codeforces Beta Round #16 div 2 C.Monitor最大公约数

    C. Monitor time limit per test 0.5 second memory limit per test 64 megabytes input standard input ou ...

  5. [codeforces 55]D. Beautiful numbers

    [codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...

  6. codeforces 483A. Counterexample 解题报告

    题目链接:http://codeforces.com/problemset/problem/483/A 题目意思:给出一个区间 [l, r],要从中找出a, b, c,需要满足 a, b 互质,b, ...

  7. codeforces B. Levko and Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/361/B 题目意思:有n个数,这些数的范围是[1,n],并且每个数都是不相同的.你需要构造一个排列,使得这 ...

  8. codeforces B. Routine Problem 解题报告

    题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划 ...

  9. CodeForces 300C --数论

    A - A Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

随机推荐

  1. mysql存储过程的学习

    平时在工作中写过很多存储过程,但有时候对某些存储过程还是有些困惑的,所以发一篇文章记录下. 标准存储过程写法 create procedure`myQueryTask`( IN Task_No VAR ...

  2. 轻量级应用开发之(03)UIVIew

    本文是我在学习OC中的一些经验总结,在学习中总结了常用的Mac技巧,欢迎群友对本文提出意见,如有问题请联系我. 一 九宫格-购物车 通过文件加载数据: NSString * file = [[NSBu ...

  3. 使用SubLineText3

    一 Sublinetext3 1. Sublime Text3是一款跨平台的编辑器, 2. 安装网址: http://www.sublimetext.com/3 二 常用使用方法 1)打开控制台: V ...

  4. Centos目录结构详细版

    使用linux也有一年多时间了  最近也是一直在维护网站系统主机  下面是linux目录结构说明 本人使用的是centos系统,很久没有发表博文了 近期会整理自己所用所了解知识点,发表linux相关的 ...

  5. 让Windows 7内置Administrator 用户也能使用指纹登录

    前言 这周末重装了个系统,之前用windows 8 现在8.1预览版出来了,琢磨着是不是给升级玩玩.装上后感觉变化不大,后来一折腾,就换回windows 7 了(64位旗舰版).将安装时创建的用户删除 ...

  6. UML(5)——协作图

    协作图中表示了角色之间的关系,通过协作图限定协作中的对象或链.协作指的是在一定的语境中一组对象以及实现某些行为的对象间的相互作用. 协 作图是表现对象协作关系的图,表示了协作中作为各种类元角色的对象所 ...

  7. delete this及堆破坏检测方法

    作者: Bruce   日期: 2012年06月03日 04:20 周日 发表评论 (0) 查看评论 --END*1--> 0 条评论 --END*2-->1,837 人阅读   程序BU ...

  8. EF图解

  9. cocos基础教程(5)数据结构介绍之cocos2d::Vector

    cocos2d::Vector cocos2d::Vector<T>是一个封装好的能动态增长顺序访问的容器.cocos2d::Vector<T>中的元素是按序存取的,它的低层实 ...

  10. Apache同时支持PHP和Python的配置方法

      一.http://www.oschina.net 网站中的一个问答内容: 原来把 WSGIScriptAlias / "D:/project/ddd/django.wsgi"  ...