题目链接:1354.Cut the Cable
Description
The company have n(n<=100) long cables(the length is not necessarily the same),we assume that the length of every long cable is an integer and not exceeded 10000 meters. Now we cut them into short cables with the same length. We are required not to waste every long cable and the length of the short cable is the longer the better. Please calculate the longest length of short cable and how many short cables after cutting.
Input
The input contains two lines.
The first line is n, represents the number of long cables.
The second line has n positive integers separated by spaces, represent the length of long cable.
Output
The first line represent the longest length of short cable.
The second line represent the number of short cables.
Sample Input
4
18 12 24 30
Sample Output
6
分析:gcd暴力
//#include<bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include<algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <cstring>
#include <string.h>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
#define MAXN 10005
#define INF 0x3f3f3f3f//将近ll类型最大数的一半,而且乘2不会爆ll
int a[105];
int gcd(int a, int b)
{
return !b? a: gcd(b, a%b);
}
int main()
{
int n, minn, sum=0;
cin >> n;
for(int i=0; i<n; ++i)
scanf("%d", &a[i]);
minn = a[0];
for(int i=1; i<n; ++i)
minn = gcd(minn, a[i]);
for(int i=0; i<n; ++i)
sum+=a[i]/minn;
cout << minn << '\n' << sum << '\n';
return 0;
}