.
问题 ∑ i , j < = n i a j a ( i , j ) b \sum_{i,j<=n}i^aj^a(i,j)^b i,j<=n∑iaja(i,j)b记 f ( d ) = ∑ ( i , j ) = d i a j a F ( d ) = ∑ d ∣ i , d ∣ j i a j a f(d)=\sum_{(i,j)=d}i^aj^a \\ F(d)=\sum_{d|i,d|j}i^aj^a f(d)=(i,j)=d∑iajaF(d)=d∣i,d∣j∑iaja可得 F ( d ) = ∑ k f ( k d ) F(d)=\sum_{k}f(kd) F(d)=k∑f(kd) f ( d ) = ∑ k F ( k d ) μ ( k ) f(d)=\sum_{k}F(kd)\mu(k) f(d)=k∑F(kd)μ(k)带入得到 ∑ d = 1 n d b f ( d ) \sum_{d=1}^nd^bf(d) d=1∑ndbf(d) = ∑ d = 1 n d b ∑ k F ( k d ) μ ( k ) =\sum_{d=1}^nd^b\sum_{k}F(kd)\mu(k) =d=1∑ndbk∑F(kd)μ(k) = ∑ i j < = n F ( i j ) i b μ ( j ) =\sum_{ij<=n}F(ij)i^b\mu(j) =ij<=n∑F(ij)ibμ(j) = ∑ T = 1 n F ( T ) ∑ d ∣ T d b μ ( T d ) =\sum_{T=1}^nF(T)\sum_{d|T}d^b\mu(\frac{T}{d}) =T=1∑nF(T)d∣T∑dbμ(dT)因为 F ( z ) = z 2 a ∑ i z < = n , j z < = n i a j a F(z)=z^{2a}\sum_{iz<=n,jz<=n}i^aj^a F(z)=z2aiz<=n,jz<=n∑iaja = z 2 a ∗ ( ∑ i = 1 n z i a ) 2 =z^{2a}*(\sum_{i=1}^{\frac{n}{z}}i^a)^2 =z2a∗(i=1∑znia)2
可以得到 G ( x ) = ∑ [ n z ] = x F ( z ) = ( ∑ i = 1 n z i a ) 2 ∗ ( ∑ z z 2 a ) G(x)=\sum_{[\frac{n}{z}]=x}F(z)=(\sum_{i=1}^{\frac{n}{z}}i^a)^2*(\sum_zz^{2a}) G(x)=[zn]=x∑F(z)=(i=1∑znia)2∗(z∑z2a)
预处理伯努利数,可以 O ( n a ) O(\sqrt{n}a) O(na)计算前缀和
让后考虑计算 μ ∗ i d b \mu*id^b μ∗idb
注意到 I ∗ μ ∗ i d b = i d b I*\mu*id^b=id^b I∗μ∗idb=idb,考虑直接杜教筛即可
.
∑ i = 1 n ∑ j = 1 n ( i j ) ( i , j ) \sum_{i=1}^n\sum_{j=1}^n(ij)^{(i,j)} i=1∑nj=1∑n(ij)(i,j)
= ∑ d = 1 n ∑ ( i , j ) = d ( i j ) d =\sum_{d=1}^n\sum_{(i,j)=d}(ij)^d =d=1∑n(i,j)=d∑(ij)d
= ∑ d = 1 n d 2 d ∑ i d < = n ∑ j d < = n ( i j ) d [ ( i , j ) = 1 ] =\sum_{d=1}^nd^{2d}\sum_{id<=n}\sum_{jd<=n}(ij)^d[(i,j)=1] =d=1∑nd2did<=n∑jd<=n∑(ij)d[(i,j)=1]
= ∑ d = 1 n d 2 d ∑ i d < = n ∑ j d < = n ( i j ) d ∑ t ∣ i , t ∣ j μ ( t ) =\sum_{d=1}^nd^{2d}\sum_{id<=n}\sum_{jd<=n}(ij)^d\sum_{t|i,t|j}\mu(t) =d=1∑nd2did<=n∑jd<=n∑(ij)dt∣i,t∣j∑μ(t)
= ∑ d = 1 , t = 1 n d 2 d μ ( t ) ∑ i , j < = n d t ( i t ) d ( j t ) d =\sum_{d=1,t=1}^nd^{2d}\mu(t)\sum_{i,j<=\frac{n}{dt}}(it)^d(jt)^d =d=1,t=1∑nd2dμ(t)i,j<=dtn∑(it)d(jt)d
= ∑ d = 1 , t = 1 n d 2 d t 2 d μ ( t ) ∑ i , j < = n d t ( i j ) d =\sum_{d=1,t=1}^nd^{2d}t^{2d}\mu(t)\sum_{i,j<=\frac{n}{dt}}(ij)^d =d=1,t=1∑nd2dt2dμ(t)i,j<=dtn∑(ij)d
记 F ( x , d ) = ∑ i , j < = x ( i j ) d F(x,d)=\sum_{i,j<=x}(ij)^d F(x,d)=∑i,j<=x(ij)d
= ∑ d t < = n d 2 d t 2 d μ ( t ) F ( n / d t , d ) =\sum_{dt<=n}d^{2d}t^{2d}\mu(t)F(n/dt,d) =dt<=n∑d2dt2dμ(t)F(n/dt,d)
发现有效的 d t dt dt只有 O ( n log n ) O(n \log n) O(nlogn),问题变为如何计算 F ( x , d ) F(x,d) F(x,d)
F ( x , d ) = ( ∑ i = 1 x i d ) 2 F(x,d)=(\sum_{i=1}^xi^d)^2 F(x,d)=(i=1∑xid)2发现需要 min ( O ( d ) , O ( x ) ) \min(O(d),O(x)) min(O(d),O(x))的复杂度来计算
于是先枚举 t t t,再卡常一下就可以了