Codeforces 389A (最大公约数)
| Time Limit: 1000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
Description
Fox Ciel is playing a game with numbers now.
Ciel has n positive integers: x1, x2, ..., 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: x1, x2, ..., xn (1 ≤ xi ≤ 100).
Output
Output a single integer — the required minimal sum.
Sample Input
2
1 2
2
3
2 4 6
6
2
12 18
12
5
45 12 27 30 18
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 - x2, x2 = x2 - x1.
Source
#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 (最大公约数)的更多相关文章
- Codeforces 660A. Co-prime Array 最大公约数
A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CodeForces 346A Alice and Bob (数学最大公约数)
题意:有一堆数,然后有两个人轮流从中取出两个数,这两个数的差的绝对值不在这个集合,然后把这个数放进这个集合,如果哪个人不能拿了,就是输了,问你谁赢. 析:当时连题意都没看好,以为拿出两个数,就不放回了 ...
- Codeforces Round #275 (Div. 2) A. Counterexample【数论/最大公约数】
A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 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 ...
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
- codeforces 483A. Counterexample 解题报告
题目链接:http://codeforces.com/problemset/problem/483/A 题目意思:给出一个区间 [l, r],要从中找出a, b, c,需要满足 a, b 互质,b, ...
- codeforces B. Levko and Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/361/B 题目意思:有n个数,这些数的范围是[1,n],并且每个数都是不相同的.你需要构造一个排列,使得这 ...
- codeforces B. Routine Problem 解题报告
题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划 ...
- CodeForces 300C --数论
A - A Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
随机推荐
- BZOJ-3668 起床困难综合症 位运算+贪心
faebdc学长杂题选讲中的题目...还是蛮简单的...位运算写的不熟练... 3668: [Noi2014]起床困难综合症 Time Limit: 10 Sec Memory Limit: 512 ...
- BZOJ-1491 社交网络 FLoyd+乱搞
感觉这两天一直在做乱搞的题... 1491: [NOI2007]社交网络 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1279 Solved: 732 ...
- BZOJ2115 [Wc2011] Xor
Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...
- JavaScript parser
JavaScript parser 和上面功能有点像,折叠JS代码,快速找到JS中类,方法的工具
- appium跑demo简单实例讲解
安装appium,设置 demo.pyfrom appium import webdriver #要装webdriver,方法查看http://www.cnblogs.com/sincoolvip/p ...
- 从注册流程 分析如何安全退出多个Activity 多种方式(附DEMO)
退出Activity注册Android遍历 目录(?)[+] 前言 知识结构 具体方案 方案1 方法采用FLAG_ACTIVITY_CLEAR_TOP退出整个程序多activity 方案2 方 ...
- jQuery返回顶部(精简版)
jQuery返回顶部(精简版) <!DOCTYPE html><html lang="en"><head> <meta charset=& ...
- 一个共通的viewModel搞定所有的编辑页面-经典ERP录入页面(easyui + knockoutjs + mvc4.0)
http://www.cnblogs.com/xqin/archive/2013/06/06/3120887.html 前言 我写代码喜欢提取一些共通的东西出来,之前的一篇博客中说了如何用一个共通的v ...
- 根据某列,将两个 dataframe 合并
import pandas as pd import numpy as np df1 = pd.DataFrame(np.array([['a', 5, 9], ['b', 4, 61], ['c', ...
- web.xml文件中的web-app元素 部署
[转载]web.xml文件中的web-app元素 (2012-05-24 13:35:57) 转载▼ 标签: 转载 分类: java 挺全 的 呵呵呵 转了 原文地址:web.xml文件中的web-a ...