欢迎大家来看我写的A+B呀

博客详细探讨了A+B问题的解决方法,利用莫比乌斯函数和数论分块技术,通过线性筛和前缀和预处理,实现了O(n+q√nlogm)的复杂度。同时,对于B问题,通过变量对称性和完全图的理解,同样运用数论分块和快速幂优化算法,达到高效的求解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

##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=1nxm=1nx13dgcd(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,dx1nxm=1,dxmnx13

=∑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)dnm1x1dnx13d3

=∑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)dnm1f(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)dnm1f(dn)

$可以用数论分块+快速幂 $

μ(d)是莫比乌斯函数\mu(d)是莫比乌斯函数μ(d)

复杂度:o(n+q∗n∗log⁡m)复杂度:o(n+q*\sqrt{n}*\log{m})o(n+qnlogm)

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=1mx1=1nxm=1n(xi2+xii=j,j=1nxj)dgcd(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=1mx1=1nxm=1n(xi2)dgcd(x1,x2,,xm)μ(d)+i=1mx1=1nxm=1nxii=j,j=1nxjdgcd(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=1nxm=1n(xi2)dgcd(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=1nxm=1n(x12)dgcd(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=mx1=1nxm=1n(x12)dgcd(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)=md=1nμ(d)x1=1,dx1nxm=1,dxmn(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=md=1nμ(d)dnm1x1=1dnx12d2

=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)=md=1nμ(d)d2dnm1g(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(m1)x1=1nxm=1nx1x2dgcd(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)^2x=1ny=1nz=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=3x=1ny=1nz=1nx2+6x=1ny=1nz=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(m1)x1=1nxm=1nx1x2dgcd(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(m1)d=1nμ(d)dnm2x1=1dnx2=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(m1)d=1nμ(d)d2dnm2(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(m1)d=1nμ(d)d2dnm2(2dn(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(m1)d=1nμ(d)d2dnm(2(1+dn))2

数论分块+快速幂数论分块+快速幂+

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值