HDU 5734 Acperience (公式推导) 2016杭电多校联合第二场
题目:传送门。
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int gcd(long long a,long long b) { if(!b) return a; return gcd(b,a%b); } int a[100005]; int main() { int T,n; scanf("%d",&T); while(T--) { long long sum=0; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]<0) a[i] = -a[i]; sum+=a[i]; } long long ap = sum,aq = n; long long g = gcd(n,sum); ap = ap/g; aq = aq/g; //printf("%I64d/%I64d\n",ap,aq); long long z=0; long long m=0; for(int i=0;i<n;i++) { z+=a[i]*a[i]; m+=2*a[i]; } long long p,q; //p = ap*ap*n; //q = aq*aq; p = n*z-sum*sum; q = n; g = gcd(q,p); p /= g; q /= g; printf("%I64d/%I64d\n",p,q); } }