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
2 1 5 2 4 2
Output
5 5 6 2
题意:在n个数里面我们要找一个值ans,使得每一个袋鼠都用这个值,和最小,(算了,不知道怎么描述)
我们当然要找gcd了,因为当gcd的时候其他的袋鼠不用买多余的饭菜,即买的都正好吃完,花的钱数当然最小,因为没有多余的支出吗,如果是其他的我们就有余数了,比他小的买一个吃不完,浪费,比他大的如果不是它的整数倍买完整数倍后还得再买一个,因为不够吃的。就是这么个理!!!(注意输=输入格式)
#include<iostream>
#include<stdio.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
ll x, sum, ans,n;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
scanf("%lld", &n);
scanf("%lld", &x);
sum = x;
ans = x;
for (int i = 2 ;i <= n; i++)
{
scanf("%lld", &x);
sum += x;
ans = gcd(ans, x);
}
cout << sum << " " << ans << endl;
}
return 0;
}