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 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 nintegers: x1x2, ..., xn (1 ≤ xi ≤ 100).

Output

Output a single integer — the required minimal sum.

Examples

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

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.

目意思:给你n个数,任意两个数直接,大数可以减去小数得到新的值再赋值给大数,如此反复,直到不出现大数和小数,即所有的数都相等。

解题思路:我看了看数据量很小,于是可以选择使用模拟的方法,将过程模拟了一下,其实能够发现这道题存在着规律,最后所有的数都会变成所有数的最大公约数。

上代码:

模拟法:

 #include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int n,i,j,ans;
int a[];
scanf("%d",&n);
for(i=; i<n; i++)
{
scanf("%d",&a[i]);
}
while()
{
sort(a,a+n);
if(a[n-]==a[])///互相减,直到都相等
{
break;
}
for(j=n-; j>; j--)
{
if(a[j]!=a[j-])
{
a[j]=a[j]-a[j-];
}
else
{
continue;
}
}
}
ans=a[]*n;
printf("%d",ans);
return ;
}

找到规律,使用GCD:

 #include<stdio.h>
#include<algorithm>
using namespace std;
int gcd(int a,int b)
{
int r;
while(b>)
{
r=a%b;
a=b;
b=r;
}
return a;
}
int main()
{
int i,k,n,ans;
int a[];
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%d",&a[i]);
}
k=a[];
for(i=;i<n;i++)
{
ans=gcd(k,a[i]);
k=ans;
}
printf("%d\n",ans*n);
return ;
}

Fox and Number Game的更多相关文章

  1. Codeforces Round #228 (Div. 2) A. Fox and Number Game

    #include <iostream> #include <algorithm> #include <vector> #include <numeric> ...

  2. Codeforces 389A (最大公约数)

    Fox and Number Game Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u ...

  3. Codeforces Round #228 (Div. 2)

    做codeforces以来题目最水的一次 A题: Fox and Number Game 题意:就是用一堆数字来回减,直到减到最小值为止,再把所有最小值加,求这个值 sol: 简单数论题目,直接求所有 ...

  4. CF 371B Fox Dividing Cheese[数论]

    B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. Codeforces Round #218 (Div. 2) B. Fox Dividing Cheese

    B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #290 (Div. 2) D. Fox And Jumping dp

    D. Fox And Jumping 题目连接: http://codeforces.com/contest/510/problem/D Description Fox Ciel is playing ...

  7. Codeforces Round #290 (Div. 2) C. Fox And Names dfs

    C. Fox And Names 题目连接: http://codeforces.com/contest/510/problem/C Description Fox Ciel is going to ...

  8. Codeforces Round #290 (Div. 2) B. Fox And Two Dots dfs

    B. Fox And Two Dots 题目连接: http://codeforces.com/contest/510/problem/B Description Fox Ciel is playin ...

  9. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

随机推荐

  1. Python豆瓣源

    pip install -i https://pypi.doubanio.com/simple/ xxxx

  2. jQuery实现 自动滚屏操作

    实现自动滚屏思路: 1.滚屏即:文本的往上移动一段距离: 2.那么我们使文本每过一段时间就往上移动一段固定距离,就可实现滚屏: 3.直到文本底部出现在浏览器窗口中,专业点就是 文本移动的距离 + 浏览 ...

  3. SASS实现代码的重用:混合器Mixin、继承

    1. 继承: @extend sass允许一个选择器,继承另一个选择器,通过@extend实现 .class1{ border: 1px solid #333; } .class2{ @extend ...

  4. Java : Spring基础 IOC

    使用 ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml" ...

  5. javascript之input字符串不为空

    今天我们来讲如何判断这个java中字符串输入是否为空 ------------------------当只有一个input的时候,我们来进行个判断这个值是否为空-------------------- ...

  6. PHP.48-TP框架商城应用实例-后台23-权限管理-权限验证

    权限验证 1.登录控制器 2.通过tp验证码类生成验证码图片 3.在管理员模型增加登录验证规则 4.后台中所有的控制器必须先登录才能访问 思路:在访问任何一个控制器之前都判断一个session即可,= ...

  7. 北京Uber优步司机奖励政策(2月28日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  8. 北京Uber优步司机奖励政策(10月5日~10月11日)

    用户组:优步北京人民优步A组(适用于10月5日-10月11日) 滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/ ...

  9. 成都Uber优步司机奖励政策(4月1日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  10. mac使用brew或者tomcat启动jenkins后配置文件路径

    在mac下使用brew命令或tomcat安装jenkins,启动后要输入密码,密码不知道,又找不到config.xml,找了半天原来 config.xml在/Users/qiaojiafei/.jen ...