题目连接:hdu_5734_Acperience
多校的题我还是贴官方题解的好,方便快捷,省事!!
1 #include<cstdio> 2 #include<cmath> 3 #define F(i,a,b) for(int i=a;i<=b;i++) 4 typedef long long ll; 5 6 ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} 7 8 int main() 9 { 10 int t,n,tp; 11 scanf("%d",&t); 12 while(t--) 13 { 14 ll fsum=0,sum=0; 15 scanf("%d",&n); 16 F(i,1,n)scanf("%d",&tp),sum+=tp>0?tp:-tp,fsum+=tp*tp; 17 sum*=sum,fsum*=n,fsum-=sum; 18 ll gc=gcd(fsum,n); 19 fsum/=gc,n/=gc; 20 printf("%lld/%d ",fsum,n); 21 } 22 }