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?
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).
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
inputCopy
2
1
5
2
4 2
outputCopy
5 5
6 2
很简单的gcd问题
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
#define LL long long
#define CLR(a,b) memset(a,(b),sizeof(a))
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define lson l,mid,st<<1
#define rson mid,r,st<<1|1
const int N = 1e6*4 + 10;
LL gcd(LL a, LL b)
{
if(b==0) return a;
return gcd(b,a%b);
}
int main()
{
int T;
scanf("%d",&T);
while(T--) {
int n;
scanf("%d",&n);
LL x;
LL sum = 0;
LL ans;
scanf("%lld",&ans);
sum += ans;
for(int i = 1; i < n; i++) {
scanf("%lld",&x);
ans = gcd(ans,x);
sum += x;
}
printf("%lld %lld\n",sum,ans);
}
return 0;
}