链接
题解
令 m = 1 0 5 m=10^5 m=105, c i c_i ci表示数字 i i i的出现次数
∑ i = 0 m ∑ j = 0 m 2 i j c i c j = ∑ i = 0 m ∑ j = 0 m ( 2 ) 2 i j c i c j = ∑ i = 0 m ∑ j = 0 m ( 2 ) ( i + j ) 2 − i 2 − j 2 c i c j = ∑ i = 0 m ∑ j = 0 m ( 2 ) ( i + j ) 2 ( ( 2 ) − i 2 c i ) ( ( 2 ) − j 2 c j ) \sum_{i=0}^m\sum_{j=0}^m 2^{ij} c_i c_j = \sum_{i=0}^m\sum_{j=0}^m (\sqrt 2)^{2ij} c_i c_j \\ =\sum_{i=0}^m\sum_{j=0}^m (\sqrt 2)^{(i+j)^2-i^2-j^2} c_i c_j \\ =\sum_{i=0}^m\sum_{j=0}^m (\sqrt 2)^{(i+j)^2} \left( (\sqrt 2)^{-i^2} c_i \right) \left( (\sqrt 2)^{-j^2} c_j \right) i=0∑mj=0∑m2ijcicj=i=0∑mj=0∑m(2)2ijcicj=i=0∑mj=0∑m(2)(i+j)2−i2−j2cicj=i=0∑mj=0∑m(2)(i+j)2((2)−i2ci)((2)−j2cj)
N T T NTT NTT做就行了
代码
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 300010
#define cl(x) memset(x,0,sizeof(x))
#define rep(_,__) for(_=1;_<=(__);_++)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
ll c, f(1);
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
for(;isdigit(c);c=getchar())x=x*10+c-0x30;
return f*x;
}
#define mod 998244353ll
ll n, c[maxn];
struct EasyMath
{
ll prime[maxn], phi[maxn], mu[maxn];
bool mark[maxn];
ll fastpow(ll a, ll b, ll c)
{
ll t(a%c), ans(1ll);
for(;b;b>>=1,t=t*t%c)if(b&1)ans=ans*t%c;
return ans;
}
void exgcd(ll a, ll b, ll &x, ll &y)
{
if(!b){x=1,y=0;return;}
ll xx, yy;
exgcd(b,a%b,xx,yy);
x=yy, y=xx-a/b*yy;
}
ll inv(ll x, ll p) //p是素数
{return fastpow(x%p,p-2,p);}
ll inv2(ll a, ll p)
{
ll x, y;
exgcd(a,p,x,y);
return (x+p)%p;
}
void shai(ll N)
{
ll i, j;
for(i=2;i<=N;i++)mark[i]=false;
*prime=0;
phi[1]=mu[1]=1;
for(i=2;i<=N;i++)
{
if(!mark[i])prime[++*prime]=i, mu[i]=-1, phi[i]=i-1;
for(j=1;j<=*prime and i*prime[j]<=N;j++)
{
mark[i*prime[j]]=true;
if(i%prime[j]==0)
{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
mu[i*prime[j]]=-mu[i];
phi[i*prime[j]]=phi[i]*(prime[j]-1);
}
}
}
ll CRT(vector<ll> a, vector<ll> m) //要求模数两两互质
{
ll M=1, ans=0, n=a.size(), i;
for(i=0;i<n;i++)M*=m[i];
for(i=0;i<n;i++)(ans+=a[i]*(M/m[i])%M*inv2(M/m[i],m[i]))%=M;
return ans;
}
}em;
struct NTT
{
ll n, R[maxn], a[maxn], b[maxn];
void init(ll bound) //bound是积多项式的最高次幂
{
ll L(0);
for(n=1;n<=bound;n<<=1,L++);
for(ll i=0;i<n;i++)R[i]=(R[i>>1]>>1)|((i&1)<<(L-1)), a[i]=b[i]=0;
}
void ntt(ll* a, int opt)
{
ll i, j, k, wn, w, x, y, inv(em.fastpow(n,mod-2,mod));
for(i=0;i<n;i++)if(i>R[i])swap(a[i],a[R[i]]);
for(i=1;i<n;i<<=1)
{
if(opt==1)wn=em.fastpow(3,(mod-1)/(i<<1),mod);
else wn=em.fastpow(3,(mod-1-(mod-1)/(i<<1)),mod);
for(j=0;j<n;j+=i<<1)
for(w=1,k=0;k<i;k++,w=w*wn%mod)
{
x=a[k+j], y=a[k+j+i]*w%mod;
a[k+j]=(x+y)%mod, a[k+j+i]=(x-y)%mod;
}
}
if(opt==-1)for(i=0;i<n;i++)(a[i]*=inv)%=mod;
}
void mult()
{
ntt(a,1), ntt(b,1);
for(int i=0;i<n;i++)(a[i]*=b[i])%=mod;
ntt(a,-1);
}
}ntt;
int main()
{
ll i, r=116195171, ans=0;
n=read();
rep(i,n)c[read()]++;
ntt.init(1e5);
for(i=0;i<=1e5;i++)ntt.a[i]=ntt.b[i]=em.fastpow(r,(mod-1-i*i%(mod-1)),mod)*c[i]%mod;
ntt.mult();
for(i=0;i<=2e5;i++)
{
(ans += ntt.a[i]*em.fastpow(r,i,mod)%mod*(i+1))%=mod;
}
printf("%lld",(ans+mod)%mod);
return 0;
}