Cheap Kangaroo()

Description

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.

Sample Input

扫描二维码关注公众号,回复: 50328 查看本文章
2
1
5
2
4 2

Sample Output

5 5

6 2

题解:同样大小的盘子,个数不同,问如何分配,只有是他们最小公约数的时候最小,此时盘子正好全满。

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn =  1e5+5;
const double Pi = acos(-1);
const int INF = 0x3f3f3f3f;
typedef long long ll;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        ll n,sum=0,ans=1;
        scanf("%lld",&n);
        for(int i=0; i<n; i++)
        {
            ll m;
            scanf("%lld",&m);
            if(i==0)
                ans=m;
            else
                ans=__gcd(ans,m);
            sum+=m;
        }
        cout<<sum<<" "<<ans<<endl;
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/Baiyi_destroyer/article/details/80053609