简要题意懒得写了,傻逼题一道。
和 LOJ520绯色IOI(开端)一模一样的结论。题解也懒得写,放个代码得了。
代码:
#include<bits/stdc++.h>
#define ll long long
#define re register
#define cs const
namespace IO{
inline char gc(){
static cs int Rlen=1<<22|1;static char buf[Rlen],*p1,*p2;
return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,Rlen,stdin),p1==p2)?EOF:*p1++;
}template<typename T>T get_integer(){
char c;bool f=false;while(!isdigit(c=gc()))f=c=='-';T x=c^48;
while(isdigit(c=gc()))x=((x+(x<<2))<<1)+(c^48);return f?-x:x;
}inline int gi(){return get_integer<int>();}
}using namespace IO;
using std::cerr;
using std::cout;
cs int N=5e3+7;
int a[N],n,m,k;
ll ans[N];bool vs[N];
ll calc(int *a,int len){
if(len==1)return (ll)a[1]*a[1];
if(len==2)return (ll)a[1]*a[2]*2;
ll res=(ll)a[len]*a[len-1]+(ll)a[len]*a[len-2];
for(int re i=len-1;i>2;--i){
res+=(ll)a[i]*a[i-2];
}res+=(ll)a[1]*a[2];
return res;
}
void Main(){n=gi();
for(int re i=1;i<=n;++i)a[i]=gi();
for(int re i=1;i<=n;++i)ans[0]+=(ll)a[i]*a[i];
m=gi();
vs[0]=vs[n]=true;ans[n]=ans[0];
std::sort(a+1,a+n+1);
while(m--){
k=std::__gcd(gi(),n);
if(vs[k]){cout<<ans[k]<<"\n";continue;}
vs[k]=true;int st=n/k;
for(int re i=0;i<n;i+=st)
ans[k]+=calc(a+i,st);
cout<<ans[k]<<"\n";
}
}
inline void file(){
#ifndef ONLINE_JUDGE
freopen("algebraic.in","r",stdin);
freopen("algebraic.out","w",stdout);
#endif
}
signed main(){file();Main();return 0;}