Squared Error 数学
题解
以a,b,c为例
(b-a)(b-a)+(c-a)(c-a)+(c-b)(c-b)=a✖a+b✖b+c✖c -(a+b+c)✖(a+b+c)
代码
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<string.h>
#include<time.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cctype>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
inline int read()
{
char ch = getchar();int x = 0, f = 1;
while(ch<'0'||ch>'9'){if(ch == '-') f = -1;ch = getchar();}
while('0'<=ch && ch <= '9'){x = x*10+ch-'0';ch = getchar();}
return x*f;
}
ll mod=1e9+7;
ll INF=1e15;
ll Inf=0x3f3f3f3f;
const int N=3e5+5;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int a;
ll sum=0;
ll ans=0;
ll n;
cin>>n;
for(ll i=0;i<n;++i)
{
a=read();
ans+=n*a*a;
sum+=a;
}
ans-=sum*sum;
cout<<ans<<endl;
return 0;
}