洛谷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=AB∑y=CD[gcd(x,y)=k]
为了满足:
F
(
k
)
=
∑
n
∣
d
f
(
d
)
F(k)=\\sum_{n|d}f(d)
F(k)=∑n∣df(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=AB∑x=CD[k∣gcd(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′=kA−1kB∑y′=kC−1kD=(⌊kB⌋−⌊kA−1⌋)∗(⌊kD⌋−⌊kC−1⌋)
根据莫比乌斯反演定理得:
f
(
k
)
=
∑
k
∣
d
μ
(
d
k
)
F
(
d
)
f(k)=\\sum_{k|d}\\mu(\\frac dk)F(d)
f(k)=∑k∣dμ(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=d′k
则 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(d′k)
∵ 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(d′k)=(⌊d′kB⌋−⌊d′kA−1⌋)∗(⌊d′kD⌋−⌊d′kC−1⌋
令 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′=kA−1,B′=k洛谷P2522 [HAOI2011]Problem b