zoukankan      html  css  js  c++  java
  • Cheap Kangaroo

    There are N kangaroos going out to eat at an Indian restaurant. The ith kangaroo wants to eat exactly xi food. The kangaroos all want to order the same size of plates, but each one can order more than one plate for themselves if they need to. If the kangaroo orders more than he needs, he can simply hide the leftovers in his pouch.

    At this Indian restaurant, the cost of the plate is the same as its size. Since Karl the Kangaroo is paying and is low on money, he wants to know what is the minimum cost to feed all N kangaroos and what is the largest possible size of the plates that satisfies this minimum cost?

    Input

    The first line of input is T – the number of test cases.

    The first line of each test case is an integer N (1 ≤ N ≤ 105).

    The second line contains N space-separated integers xi (1 ≤ xi ≤ 109).

    Output

    For each test case, output a line containing two space-separated integers – the minimum cost and the maximum plate size that corresponds to when the total cost is minimized.

    Example

    input

    Copy

    2
    1
    5
    2
    4 2
    

    output

    Copy

    5 5
    6 2

    题意:先是和,后是最大公约数

    #include<algorithm>
    #include<stdlib.h>
    #include<stdio.h>
    #include<string.h>
    using namespace std;
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            long long int n,i,k,a[100100],sum=0;
            scanf("%lld",&n);
            for(i=0;i<n;i++)
               scanf("%lld",&a[i]);
            k=a[0];
            for(i=1;i<n;i++)
            {
                k=__gcd(k,a[i]);
            }
            for(i=0;i<n;i++ )
              sum+=a[i];
            printf("%lld %lld
    ",sum,k);
        }
        return 0;
    }
  • 相关阅读:
    在vim中设置将tab自动转化为4个空格
    nginx1.4.6+php5.5.11+mysql5.6.17+mecache+opcache
    Centos7安装杀毒软件ClamAV
    网页中meta标记
    js刷新页面方法大全
    微信第三方登陆,无需注册一键登录,获取用户信息,PHP实现方法
    phpcms v9 如何实现用户登录
    web页面自适应手机屏幕宽度
    微信公共平台消息回复类
    自动回复微信消息
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702813.html
Copyright © 2011-2022 走看看