[国家集训队] Crash的数字表格/JZPTAB(莫比乌斯反演)

[国家集训队] Crash的数字表格/JZPTAB

Statement

计算: A n s = ∑ i = 1 N ∑ j = 1 M lcm ( i , j ) Ans=\sum_{i=1}^N\sum_{j=1}^M\text{lcm}(i,j) Ans=i=1Nj=1Mlcm(i,j).

Solution

∑ i = 1 N ∑ j = 1 M lcm ( i , j ) = ∑ i = 1 N ∑ j = 1 M i ⋅ j gcd ⁡ ( i , j ) \sum_{i=1}^N\sum_{j=1}^M\text{lcm}(i,j)=\sum_{i=1}^N\sum_{j=1}^M\frac{i\cdot j}{\gcd(i,j)} i=1Nj=1Mlcm(i,j)=i=1Nj=1Mgcd(i,j)ij.

  • A n s = ∑ d = 1 m i n ( N , M ) 1 d ∑ i = 1 N ∑ j = 1 M i ⋅ j [ gcd ⁡ ( i , j ) = d ] Ans=\sum_{d=1}^{min(N,M)}\frac{1}{d}\sum_{i=1}^N\sum_{j=1}^Mi\cdot j[\gcd(i,j)=d] Ans=d=1min(N,M)d1i=1Nj=1Mij[gcd(i,j)=d]

f ( d ) = ∑ i = 1 N ∑ j = 1 M i ⋅ j [ gcd ⁡ ( i , j ) = d ] f(d)=\sum_{i=1}^N\sum_{j=1}^Mi\cdot j[\gcd(i,j)=d] f(d)=i=1Nj=1Mij[gcd(i,j)=d].

g ( d ) = ∑ d ∣ d ′ f ( d ′ ) = ∑ i = 1 N ∑ j = 1 M i ⋅ j [ d ∣ gcd ⁡ ( i , j ) ] = ∑ i = 1 N ∑ j = 1 M i ⋅ j [ d ∣ i ] [ d ∣ j ] g(d)=\sum_{d|d'}f(d')=\sum_{i=1}^N\sum_{j=1}^Mi\cdot j[d|\gcd(i,j)]=\sum_{i=1}^N\sum_{j=1}^Mi\cdot j[d|i][d|j] g(d)=ddf(d)=i=1Nj=1Mij[dgcd(i,j)]=i=1Nj=1Mij[di][dj].

g ( d ) = ∑ i = 1 N i [ d ∣ i ] ∑ j = 1 M j [ d ∣ j ] = [ d ( 1 + ⌊ N d ⌋ ) ⌊ N d ⌋ 2 ] × [ d ( 1 + ⌊ M d ⌋ ) ( ⌊ M d ⌋ ) 2 ] g(d)=\sum_{i=1}^Ni[d|i]\sum_{j=1}^Mj[d|j]=[d\frac{(1+\lfloor\frac{N}{d}\rfloor)\lfloor\frac{N}{d}\rfloor}{2}]\times[d\frac{(1+\lfloor\frac{M}{d}\rfloor)(\lfloor\frac{M}{d}\rfloor)}{2}] g(d)=i=1Ni[di]j=1Mj[dj]=[d2(1+dN)dN]×[d2(1+dM)(dM)].

f ( d ) = ∑ d ∣ d ′ μ ( d ′ d ) g ( d ′ ) = ∑ d ∣ d ′ μ ( d ′ d ) ⋅ d ′ 2 ⋅ [ ( 1 + ⌊ N d ⌋ ) ⌊ N d ⌋ 2 ] × [ ( 1 + ⌊ M d ⌋ ) ( ⌊ M d ⌋ ) 2 ] f(d)=\sum_{d|d'}\mu(\frac{d'}{d})g(d')=\sum_{d|d'}\mu(\frac{d'}{d})\cdot d'^2\cdot[\frac{(1+\lfloor\frac{N}{d}\rfloor)\lfloor\frac{N}{d}\rfloor}{2}]\times[\frac{(1+\lfloor\frac{M}{d}\rfloor)(\lfloor\frac{M}{d}\rfloor)}{2}] f(d)=ddμ(dd)g(d)=ddμ(dd)d2[2(1+dN)dN]×[2(1+dM)(dM)].

不妨设 g ( n , m ) = ( 1 + n ) n 2 × ( 1 + m ) m 2 g(n,m)=\frac{(1+n)n}{2}\times\frac{(1+m)m}{2} g(n,m)=2(1+n)n×2(1+m)m.

整理可得:
A n s = ∑ d = 1 min ⁡ ( N , M ) 1 d f ( d ) = ∑ d = 1 min ⁡ ( N , M ) 1 d ∑ d ∣ d ′ μ ( d ′ d ) ⋅ d ′ 2 ⋅ g ( ⌊ N d ′ ⌋ , ⌊ M d ′ ⌋ ) = ∑ d = 1 min ⁡ ( N , M ) d ∑ t = 1 min ⁡ ( N d , M d ) μ ( t ) ⋅ t 2 ⋅ g ( ⌊ N t d ⌋ , ⌊ M t d ⌋ ) \begin{aligned} Ans&=\sum_{d=1}^{\min(N,M)}\frac{1}{d}f(d)\\ &=\sum_{d=1}^{\min(N,M)}\frac{1}{d}\sum_{d|d'}\mu(\frac{d'}{d})\cdot d'^2\cdot g(\lfloor\frac{N}{d'}\rfloor,\lfloor\frac{M}{d'}\rfloor)\\ &=\sum_{d=1}^{\min(N,M)}d\sum_{t=1}^{\min(\frac{N}{d},\frac{M}{d})}\mu(t)\cdot t^2\cdot g(\lfloor\frac{N}{td}\rfloor,\lfloor\frac{M}{td}\rfloor) \end{aligned} Ans=d=1min(N,M)d1f(d)=d=1min(N,M)d1ddμ(dd)d2g(dN,dM)=d=1min(N,M)dt=1min(dN,dM)μ(t)t2g(tdN,tdM)
我们不妨设: S u m ( n , m ) = ∑ i = 1 min ⁡ ( n , m ) μ ( i ) ⋅ i 2 ⋅ g ( ⌊ n i ⌋ , ⌊ m i ⌋ ) Sum(n,m)=\sum_{i=1}^{\min(n,m)}\mu(i)\cdot i^2\cdot g(\lfloor\frac{n}{i}\rfloor,\lfloor\frac{m}{i}\rfloor) Sum(n,m)=i=1min(n,m)μ(i)i2g(in,im).

可得 A n s = ∑ d = 1 min ⁡ ( N , M ) d ⋅  sum  ( ⌊ N d ⌋ , ⌊ M d ⌋ ) Ans=\sum_{d=1}^{\min(N,M)}d\cdot\text{ sum }(\lfloor\frac{N}{d}\rfloor,\lfloor\frac{M}{d}\rfloor) Ans=d=1min(N,M)d sum (dN,dM).

时间复杂度-二次数论分块: O ( N × N ) = O ( N ) O(\sqrt{N}\times\sqrt{N})=O(N) O(N ×N )=O(N).

Link

[1] [国家集训队]Crash的数字表格/JZPTAB

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值