Project Euler 530
设
[f(n)=sum_{d vert n}(d,frac{n}{d})\
F(n)= sum_{i=1}^n{f(i)}
]
求(F(n),nleq 10^{15}, Q=1)
sol:
无法直接转化(f(n)),尝试暴力展开(f(i))后直接莫比乌斯反演转化(F(n )):
[egin{aligned}
F(n) &= sum_{i=1}^nsum_{dvert n}(d,frac{n}{d})\
&=sum_d{dsum_{i=1}^n{sum_{evert i}{[(e,frac{i}{e})=d]}}}\
&=sum_{d}dsum_{i=1}^{n/d^2}sum_{evert i}[(e,frac{i}{e})=1]\
&=sum_{d}dsum_{i=1}^{n/d^2}sum_{evert i}sum_{jvert e}sum_{jvert(i/e)}mu(e)\
&=sum_{d}sum_{j=1}^{n/d^2}dspace mu(j)sum_{i=1}^{n/d^2}sum_{evert i}[jvert e][jvert frac{i}{e}]\
&=sum_{d}sum_{j=1}^{n/d^2}dspacemu(j)sum_{i=1}^{n/d^2j^2}sigma_0(i)
end{aligned}
]
发现其实将(j)的上界扩展到(n)不会产生任何影响
[F(n)=sum_{d}sum_{j=1}^{n}dspace mu(j)sum_{i=1}^{n/d^2j^2}sigma_0(i)
]
考虑枚举(T=dj),设(S(n)=sum_{i=1}^nsigma_0(i)),发现(id)和(mu)构成卷积。
[F(n)=sum_{T=dj=1}^nphi(T)S(lfloorfrac{n}{T^2}
floor)
]
当(d>sqrt n)(frac{n}{T^2})恒为0,因此缩小枚举(T)的上界为(sqrt n),同时(S(n))可以分块优化。
[F(n)=sum_{T=dj=1}^{sqrt n}phi(T)S(lfloorfrac{n}{T ^2}
floor)
]
复杂度(sqrt n ln sqrt n) 反正是提答