洛谷P2522- [HAOI2011]Problem b - 莫比乌斯反演+杜教筛+数论分块

Posted Chivas_/Regal

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了洛谷P2522- [HAOI2011]Problem b - 莫比乌斯反演+杜教筛+数论分块相关的知识,希望对你有一定的参考价值。

题目:
在这里插入图片描述
思路:
题意让求:
f ( k ) = ∑ x = A B ∑ y = C D [ g c d ( x , y ) = k ] f(k)=\\sum_{x=A}^B\\sum_{y=C}^D[gcd(x,y)=k] f(k)=x=ABy=CD[gcd(x,y)=k]

为了满足:
F ( k ) = ∑ n ∣ d f ( d ) F(k)=\\sum_{n|d}f(d) F(k)=ndf(d)

设:
F ( k ) = ∑ x = A B ∑ x = C D [ k ∣ g c d ( x , y ) ] F(k)=\\sum_{x=A}^B\\sum_{x=C}^D[k|gcd(x,y)] F(k)=x=ABx=CD[kgcd(x,y)]

为使枚举的 x , y x,y x,y均为 k k k的倍数
x ′ = x k , y ′ = y k x' = \\frac xk,\\quad y' = \\frac yk x=kx,y=ky,我们枚举倍数
F ( k ) = ∑ x ′ = A − 1 k B k ∑ y ′ = C − 1 k D k = ( ⌊ B k ⌋ − ⌊ A − 1 k ⌋ ) ∗ ( ⌊ D k ⌋ − ⌊ C − 1 k ⌋ ) F(k)=\\sum_{x'=\\frac{A - 1}{k}}^{\\frac Bk}\\sum_{y'=\\frac{C-1}{k}}^{\\frac Dk}=(\\left \\lfloor \\frac Bk \\right \\rfloor-\\left \\lfloor \\frac{A-1}k \\right \\rfloor)*(\\left \\lfloor \\frac Dk\\right \\rfloor -\\left \\lfloor \\frac{C-1}k \\right \\rfloor) F(k)=x=kA1kBy=kC1kD=(kBkA1)(kDkC1)

根据莫比乌斯反演定理得:
f ( k ) = ∑ k ∣ d μ ( d k ) F ( d ) f(k)=\\sum_{k|d}\\mu(\\frac dk)F(d) f(k)=kdμ(kd)F(d)
为了使枚举到的d均为k的倍数
我们设 d ′ = d k H ′ = H k d' = \\frac dk\\quad H'=\\frac Hk d=kdH=kH,此时 d = d ′ k d=d'k d=dk

f ( k ) = ∑ d ′ = 1 m i n ( B k , D k ) μ ( d ′ ) F ( d ′ k ) f(k)=\\sum_{d'=1}^{min(\\frac Bk,\\frac Dk)}\\mu(d')F(d'k) f(k)=d=1min(kB,kD)μ(d)F(dk)

∵ F ( d ′ k ) = ( ⌊ B d ′ k ⌋ − ⌊ A − 1 d ′ k ⌋ ) ∗ ( ⌊ D d ′ k ⌋ − ⌊ C − 1 d ′ k ⌋ \\because F(d'k)=(\\left \\lfloor \\frac B{d'k} \\right \\rfloor-\\left \\lfloor \\frac{A-1}{d'k} \\right \\rfloor)*(\\left \\lfloor \\frac D{d'k}\\right \\rfloor -\\left \\lfloor \\frac{C-1}{d'k} \\right \\rfloor F(dk)=(dkBdkA1)(dkDdkC1

A ′ = A − 1 k , B ′ = B k , C ′ = C − 1 k , D ′ = D k A'=\\frac{A-1}k,\\quad B'=\\frac Bk,\\quad C'=\\frac{C-1}k,\\quad D'=\\frac Dk A=kA1,B=k洛谷P2522 [HAOI2011]Problem b

「Luogu2522」[HAOI2011]Problem b

luogu2522 [HAOI2011]Problem b

luogu2522 [HAOI2011]Problem b

P2522 [HAOI2011]Problem b

P2522 [HAOI2011]Problem b(莫反&整除分块)