1354.Cut the Cable SDNUOJ 1354

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
14

#include <iostream>
#include <cstdio>
using namespace std;

int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}

int a[105];

int main()
{
    int n;
    while(cin >> n)
    {
        scanf("%d", &a[0]);
        int sum = a[0];
        int mod = a[0];
        for(int i = 1; i < n; ++i)
        {
            scanf("%d", &a[i]);
            sum += a[i];
            mod = gcd(a[i], mod);
        }
        cout << mod << '\n' << sum / mod << '\n';
    }
}

全部评论

相关推荐

尊嘟假嘟点击就送:加v细说,问题很大
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务