##A+B
感谢大李老板友情赞助防ak,赛前打包票两个人尝试没有人能过嘻嘻嘻
A=∑x1=1n⋅⋅⋅∑xm=1nx13∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)A= \sum_{x_1=1}^{n} \cdot \cdot \cdot \sum_{x_m=1}^{n} x_1^3 \sum_{d|gcd(x_1,x_2,\cdot\cdot\cdot,x_m)}{\mu(d)}A=∑x1=1n⋅⋅⋅∑xm=1nx13∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)
=∑d=1nμ(d)∑x1=1,d∣x1n⋅⋅⋅∑xm=1,d∣xmn∗x13= \sum_{d=1} ^ {n} \mu (d) \sum_{x_1=1,d|x_1} ^ {n} \cdot \cdot \cdot \sum_{x_m=1,d|x_m} ^ {n}*x_1 ^ 3=∑d=1nμ(d)∑x1=1,d∣x1n⋅⋅⋅∑xm=1,d∣xmn∗x13
=∑d=1nμ(d)∗⌊nd⌋m−1∗∑x1ndx13∗d3=\sum_{d=1}^n {\mu(d)}*\lfloor \frac{n}{d} \rfloor^{m-1} *\sum_{x_1}^{\frac{n}{d}}x_1^3*d^3=∑d=1nμ(d)∗⌊dn⌋m−1∗∑x1dnx13∗d3
=∑d=1nd3μ(d)⌊nd⌋m−1∗f(⌊nd⌋)=\sum_{d=1}^{n}d^3\mu(d)\lfloor \frac{n}{d}\rfloor^{m-1}*f(\lfloor \frac{n}{d}\rfloor)=∑d=1nd3μ(d)⌊dn⌋m−1∗f(⌊dn⌋)
f(n)=n2(n+1)24f(n)=\frac{n^2(n+1)^2}{4}f(n)=4n2(n+1)2其中 ∑d3μ(d)\sum d^3\mu(d)∑d3μ(d)
用线性筛+前缀和预处理o(n)用线性筛 +前缀和预处理o(n)用线性筛+前缀和预处理o(n)当然直接暴力好像也不是不可以
⌊nd⌋m−1f(⌊nd⌋)\lfloor \frac{n}{d}\rfloor^{m-1}f(\lfloor \frac{n}{d}\rfloor)⌊dn⌋m−1f(⌊dn⌋)
$可以用数论分块+快速幂 $
μ(d)是莫比乌斯函数\mu(d)是莫比乌斯函数μ(d)是莫比乌斯函数
复杂度:o(n+q∗n∗logm)复杂度:o(n+q*\sqrt{n}*\log{m})复杂度:o(n+q∗n∗logm)
B=∑i=1m∑x1=1n⋅⋅⋅∑xm=1n(xi2+xi∗∑i≠j,j=1nxj)∗∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)B=\sum_{i=1}^{m}\sum_{x_1=1}^{n} \cdot\cdot\cdot \sum_{x_m=1}^{n}{(x_i^2+x_i*\sum_{i\neq j,j=1}^{n}x_j) }*\sum_{d|gcd(x_1,x_2,\cdot\cdot\cdot,x_m)}\mu(d)B=∑i=1m∑x1=1n⋅⋅⋅∑xm=1n(xi2+xi∗∑i=j,j=1nxj)∗∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)
=∑i=1m∑x1=1n⋅⋅⋅∑xm=1n(xi2)∗∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)+∑i=1m∑x1=1n⋅⋅⋅∑xm=1nxi∗∑i≠j,j=1nxj∗∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)=\sum_{i=1}^{m}\sum_{x_1=1}^{n} \cdot\cdot\cdot\sum_{x_m=1}^{n}(x_i^2)*\sum_{d|gcd(x_1,x_2,\cdot\cdot\cdot,x_m)}\mu(d)+\sum_{i=1}^{m}\sum_{x_1=1}^{n} \cdot\cdot\cdot \sum_{x_m=1}^{n}x_i*\sum_{i\neq j,j=1}^{n}x_j*\sum_{d|gcd(x_1,x_2,\cdot\cdot\cdot,x_m)}\mu(d)=∑i=1m∑x1=1n⋅⋅⋅∑xm=1n(xi2)∗∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)+∑i=1m∑x1=1n⋅⋅⋅∑xm=1nxi∗∑i=j,j=1nxj∗∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)
=P+Q=P+Q=P+Q
由于对称性,知∀i∈[1,m],有\forall i\in [1,m],有∀i∈[1,m],有
∑x1=1n⋅⋅⋅∑xm=1n(xi2)∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)\sum_{x_1=1} ^ {n} \cdot \cdot \cdot \sum_{x_m=1} ^ {n}(x_i ^ 2) \sum_{ d |gcd ( x _ 1,x _ 2,\cdot\cdot\cdot,x_m)}\mu(d)∑x1=1n⋅⋅⋅∑xm=1n(xi2)∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)
=∑x1=1n⋅⋅⋅∑xm=1n(x12)∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)=\sum_{x_1=1}^{n}\cdot \cdot \cdot\sum_{x_m=1}^{n}(x_1^2)\sum_{d|gcd(x_1,x_2,\cdot\cdot\cdot,x_m)}\mu(d)=∑x1=1n⋅⋅⋅∑xm=1n(x12)∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)
P=m∗∑x1=1n⋅⋅⋅∑xm=1n(x12)∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)P=m*\sum_{x_1=1}^{n}\cdot \cdot \cdot\sum_{x_m=1}^{n}(x_1^2)\sum_{d|gcd(x_1,x_2,\cdot\cdot\cdot,x_m)}\mu(d)P=m∗∑x1=1n⋅⋅⋅∑xm=1n(x12)∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)
=m∗∑d=1nμ(d)∗∑x1=1,d∣x1n⋅⋅⋅∑xm=1,d∣xmn(x12)=m*\sum_{d=1}^{n}\mu(d)*\sum_{x_1=1,d|x_1}^{n}\cdot \cdot \cdot\sum_{x_m=1,d|x_m}^{n}(x_1^2)=m∗∑d=1nμ(d)∗∑x1=1,d∣x1n⋅⋅⋅∑xm=1,d∣xmn(x12)
=m∗∑d=1nμ(d)⌊nd⌋m−1∑x1=1ndx12∗d2=m*\sum_{d=1}^{n}\mu(d)\lfloor \frac{n}{d}\rfloor^{m-1}\sum_{x_1=1}^{\frac{n}{d}}x_1^2*d^2=m∗∑d=1nμ(d)⌊dn⌋m−1∑x1=1dnx12∗d2
=m∗∑d=1nμ(d)d2⌊nd⌋m−1∗g(⌊nd⌋)=m*\sum_{d=1}^{n}\mu(d)d^2\lfloor \frac{n}{d}\rfloor^{m-1}*g(\lfloor \frac{n}{d}\rfloor)=m∗∑d=1nμ(d)d2⌊dn⌋m−1∗g(⌊dn⌋)
其中,g(n)=n(n+1)(2n+1)6其中,g(n)=\frac{n(n+1)(2n+1)}{6}其中,g(n)=6n(n+1)(2n+1)
预处理∑d2μ(d)预处理 \sum {d^2\mu(d)}预处理∑d2μ(d)
数论分块+快速幂数论分块+快速幂数论分块+快速幂
o(n+qnlogm)o(n+q\sqrt n log{m})o(n+qnlogm)
$ 同理Q$
Q=m(m−1)∑x1=1n⋅⋅⋅∑xm=1nx1x2∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)Q=m(m-1)\sum_{x_1=1}^{n} \cdot\cdot\cdot \sum_{x_m=1}^{n}x_1x_2\sum_{d|gcd(x_1,x_2,\cdot\cdot\cdot,x_m)}\mu(d)Q=m(m−1)∑x1=1n⋅⋅⋅∑xm=1nx1x2∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)
不理解的可以手推(x+y+z)2不理解的可以手推(x+y+z)^2不理解的可以手推(x+y+z)2
∑x=1n∑y=1n∑z=1n(x+y+z)2\sum_{x=1}^{n}\sum_{y=1}^{n}\sum_{z=1}^{n}(x+y+z)^2∑x=1n∑y=1n∑z=1n(x+y+z)2
=3∑x=1n∑y=1n∑z=1nx2+6∗∑x=1n∑y=1n∑z=1nxy=3\sum_{x=1}^{n}\sum_{y=1}^{n}\sum_{z=1}^{n}x^2+6*\sum_{x=1}^{n}\sum_{y=1}^{n}\sum_{z=1}^{n}xy=3∑x=1n∑y=1n∑z=1nx2+6∗∑x=1n∑y=1n∑z=1nxy
或者借助完全图来理解变量之间的对称
Q=m(m−1)∑x1=1n⋅⋅⋅∑xm=1nx1x2∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)Q=m(m-1)\sum_{x_1=1}^{n} \cdot\cdot\cdot \sum_{x_m=1}^{n}x_1x_2\sum_{d|gcd(x_1,x_2,\cdot\cdot\cdot,x_m)}\mu(d)Q=m(m−1)∑x1=1n⋅⋅⋅∑xm=1nx1x2∑d∣gcd(x1,x2,⋅⋅⋅,xm)μ(d)
=m(m−1)∑d=1nμ(d)⌊nd⌋m−2∗∑x1=1nd∑x2=1ndd2x1x2=m(m-1)\sum_{d=1}^n\mu(d)\lfloor \frac{n}{d}\rfloor^{m-2}*\sum_{x_1=1}^{\frac{n}{d}}\sum_{x_2=1}^{\frac{n}{d}}d^2x_1x_2=m(m−1)∑d=1nμ(d)⌊dn⌋m−2∗∑x1=1dn∑x2=1dnd2x1x2
=m(m−1)∑d=1nμ(d)d2⌊nd⌋m−2∗(∑x1=1ndx1)2=m(m-1)\sum_{d=1}^n\mu(d)d^2\lfloor \frac{n}{d}\rfloor^{m-2}*(\sum_{x_1=1}^{\frac{n}{d}}x_1)^2=m(m−1)∑d=1nμ(d)d2⌊dn⌋m−2∗(∑x1=1dnx1)2
=m(m−1)∑d=1nμ(d)d2⌊nd⌋m−2∗(⌊nd⌋(1+⌊nd⌋)2)2=m(m-1)\sum_{d=1}^n\mu(d)d^2\lfloor \frac{n}{d}\rfloor^{m-2}*(\frac{\lfloor\frac{n}{d}\rfloor(1+\lfloor\frac{n}{d}\rfloor) }{2})^2=m(m−1)∑d=1nμ(d)d2⌊dn⌋m−2∗(2⌊dn⌋(1+⌊dn⌋))2
=m(m−1)∑d=1nμ(d)d2⌊nd⌋m((1+⌊nd⌋)2)2=m(m-1)\sum_{d=1}^n\mu(d)d^2\lfloor \frac{n}{d}\rfloor^{m}(\frac{(1+\lfloor\frac{n}{d}\rfloor) }{2})^2=m(m−1)∑d=1nμ(d)d2⌊dn⌋m(2(1+⌊dn⌋))2
数论分块+快速幂数论分块+快速幂数论分块+快速幂