题目链接
把题目的公式展开后,就是二次函数,然后在对称轴取到最小值
ymin = n*a-a*a/n
#include<bits/stdc++.h>
using namespace std;
#define cl(a,b) memset(a,b,sizeof(a))
#define LL long long
#define gcd __gcd
const int maxn = 1e4+200;
const int inf = 1 << 23;
int main(){
int T;scanf("%d",&T);
while(T--){
LL n;scanf("%lld",&n);
LL a=0,b=0,c=0;
for(int i=0;i<n;i++){
LL x;scanf("%lld",&x);
a+=x*x;
c+=abs(x);
}
LL A = a*n-c*c;
LL B = n;
LL tmp = gcd(A,B);
printf("%lld/%lld\n",A/tmp,B/tmp);
}
return 0;
}