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. 个人对js面向对象和封装插件的用法

    做了一段时间的前端了,给自己写代码也总结出来了一点小小的思路,就来分享一下自己的意见和建议了. 面向对象和插件封装其实说到底都是面向对象的思想,但是插件一般是你要用的时候就new 调用出来的.就说一下 ...

  2. vue-cli 3.0 使用axios配置跨域访问豆瓣接口

    vue-cli 3.0 配置axios跨域访问豆瓣接口 自己做的小demo 由于豆瓣api跨域问题,因此不能直接通过ajax请求访问,我们通过vue-cli提供给我们的代理 进行配置即可, 在根目录下 ...

  3. Ajax的open()方法

    Ajax的open()方法有3个参数:1.method:2.url:3.boolean: 参数1有get和post两个取值 参数2表示什么就不用说了 重点说下第3个参数:boolean的取值 当该bo ...

  4. mysql的length与char_length的区别

    length:   是计算字段的长度一个汉字是算三个字符,一个数字或字母算一个字符 char_length:不管汉字还是数字或者是字母都算是一个字符 同时这两个函数,可用于判断数据中是否有中文文字 例 ...

  5. ES6 imports用法

    import defaultExport from "module-name"; import * as name from "module-name"; // ...

  6. s3c2440中断控制器操作

    一.ARM中断体系结构 arm有7中异常工作模式 用户模式.快中断模式.管理模式.数据访问终止模式.中断模式.系统模式.未定义指令终止模式. 几种模式有什么不同呢, 1.不同的寄存器 2.不同的权限 ...

  7. python--模块之os操作文件模块

    作用:OS又名为:操作系统.所以就是操作系统相关的功能.可以处理文件和目录这些我们日常手动需要做的操作,比如:显示当前目录下所有文件.删除某个文件.获取文件大小...os模块是与操作系统交互的一个接口 ...

  8. PC环境搭建——虚拟机配置双网卡

    Vmware虚拟机三种网络模式详解 TCP/IP协议四层模型: 应用层 传输层 网络层 物理接口 桥接模式时,主机和虚拟机在同一个网段,之间可以相互访问 NAT模式时,主机和虚拟机不在同一网段,之间通 ...

  9. JZ2440开发板:用按键点亮LED灯(学习笔记)

    本文是对韦东山嵌入式第一期学习的记录之一,如有您需要查找的信息,可以继续往下阅读. 想要用按键点亮LED灯,就需要知道按键和LED灯的相关信息,这样才可以进行之后的操作.阅读JZ2440的原理图,可以 ...

  10. Jetson tx2 串口通信

    主要参考了这篇博客:https://blog.csdn.net/zomb1e0117/article/details/85157014 其中需要注意的是最后的时候cutecom端口需要把设备改为:/d ...