C
来源:互联网 发布:java平方怎么表示 编辑:程序博客网 时间:2024/06/11 02:52
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
#include<cstdio>#include<iostream>#include<algorithm>#include<map>#include<cstring>using namespace std;const int MAX = 1e6+10;long long a[MAX];long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}int main(){ int t; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); long long n; long long sum=0; scanf("%lld",&n); for(long long i=0;i<n;i++) { scanf("%lld",&a[i]); } if(n==1) { printf("%lld %lld\n",a[0],a[0]); } else { long long minn = gcd(a[0],a[1]); for(long long i=1;i<n;i++) { minn=gcd(minn,a[i]); } for(long long i=0;i<n;i++) { int n1=a[i]/minn; int n2=a[i]%minn; if(n2==0) { sum+=a[i]; } else { sum=sum+((n1+1)*minn); } } printf("%lld %lld\n",sum,minn); } } return 0;}
- c
- c
- c
- c
- C
- c
- c
- c
- C+
- c
- C
- c
- c
- c
- C
- C
- c
- C
- Maven常用命令详情
- Reactor模式和NIO
- 在centos linux 环境下使用火焰图
- c语言二分查找算法
- Maven介绍与安装
- C
- 什么是Spring Boot?
- 区块链技术
- HikariCP-史上最快速的连接池
- Ehcache介绍及整合Spring实现高速缓存
- 浅谈浏览器的缓存机制
- armeabi中so文件兼容问题,异常java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList
- 2017年JAVA面试题锦集
- flock防止crontab重复执行脚本