莫比乌斯反演题目式子推导

文章目录

      • YY的GCD
      • 能量采集
      • [SDOI2014]数表
      • [SDOI2017]数字表格
      • [POI2007]ZAP-Queries
      • [HAOI2011]Problem b
      • [SDOI2015]约数个数和
      • [CQOI2015]选数
      • 常见积性函数与迪利克雷卷积(用于杜教筛)
      • 简单的数学题

约定:若有 n , m n, m n,m 两参数,默认 n ≤ m n \leq m nm

YY的GCD

∑ i = 1 n ∑ j = 1 m [ gcd ⁡ ( i , j ) = prime ] \sum_{i=1}^n \sum_{j=1}^m [\gcd(i,j)=\text{prime}] i=1nj=1m[gcd(i,j)=prime]

= ∑ p ∈ prime ∑ i = 1 ⌊ n p ⌋ ∑ j = 1 ⌊ m p ⌋ [ gcd ⁡ ( i , j ) = 1 ] =\sum_{p \in \text{prime}} \sum_{i=1}^{\lfloor \frac{n}{p} \rfloor} \sum_{j=1}^{\lfloor \frac{m}{p} \rfloor} [\gcd(i,j)=1] =pprimei=1pnj=1pm[gcd(i,j)=1]

= ∑ p ∈ prime ∑ i = 1 ⌊ n p ⌋ ∑ j = 1 ⌊ m p ⌋ ∑ d ∣ gcd ⁡ ( i , j ) μ ( d ) =\sum_{p \in \text{prime}} \sum_{i=1}^{\lfloor \frac{n}{p} \rfloor} \sum_{j=1}^{\lfloor \frac{m}{p} \rfloor} \sum_{d|\gcd(i,j)} \mu(d) =pprimei=1pnj=1pmdgcd(i,j)μ(d)

= ∑ p ∈ prime ∑ i = 1 m i n ( ⌊ n p ⌋ , ⌊ n p ⌋ ) μ ( i ) ⌊ n p i ⌋ ⌊ m p i ⌋ =\sum_{p \in \text{prime}} \sum_{i=1}^{min(\lfloor \frac{n}{p} \rfloor,\lfloor \frac{n}{p} \rfloor)} \mu(i) \lfloor \frac{n}{pi} \rfloor \lfloor \frac{m}{pi} \rfloor =pprimei=1min(pn,pn)μ(i)pinpim

= ∑ i = 1 m i n ( n , m ) ⌊ n i ⌋ ⌊ m i ⌋ ∑ p ∈ prime , p ∣ i μ ( i p ) =\sum_{i=1}^{min(n,m)} \lfloor \frac{n}{i} \rfloor \lfloor \frac{m}{i} \rfloor \sum_{p \in \text{prime},p|i} \mu(\dfrac{i}{p}) =i=1min(n,m)inimpprime,piμ(pi)

预处理 ∑ p ∈ prime , p ∣ i μ ( i p ) \sum_{p \in \text{prime},p|i} \mu(\dfrac{i}{p}) pprime,piμ(pi) 即可


能量采集

∑ i = 1 n ∑ j = 1 m 2 gcd ⁡ ( i , j ) − 1 \sum_{i=1}^n \sum_{j=1}^m 2 \gcd(i,j) -1 i=1nj=1m2gcd(i,j)1

= ( 2 ∑ i = 1 n ∑ j = 1 m gcd ⁡ ( i , j ) ) − n m = \left( 2 \sum_{i=1}^n \sum_{j=1}^m \gcd(i,j) \right)- nm =(2i=1nj=1mgcd(i,j))nm

= ( 2 ∑ i = 1 n ∑ x = 1 ⌊ n i ⌋ ∑ y = 1 ⌊ m i ⌋ i [ gcd ⁡ ( x , y ) = 1 ] ) − n m = \left( 2 \sum_{i=1}^n \sum_{x=1}^{\lfloor \frac{n}{i} \rfloor} \sum_{y=1}^{\lfloor \frac{m}{i} \rfloor} i[\gcd(x,y)=1] \right) - nm =2i=1nx=1iny=1imi[gcd(x,y)=1]nm

= ( 2 ∑ i = 1 n ∑ x = 1 ⌊ n i ⌋ ∑ y = 1 ⌊ m i ⌋ i ∑ d ∣ gcd ⁡ ( x , y ) μ ( d ) ) − n m = \left( 2 \sum_{i=1}^n \sum_{x=1}^{\lfloor \frac{n}{i} \rfloor} \sum_{y=1}^{\lfloor \frac{m}{i} \rfloor} i \sum_{d|\gcd(x,y)} \mu(d) \right) - nm =2i=1nx=1iny=1imidgcd(x,y)μ(d)nm

= ( 2 ∑ i = 1 n ∑ j = 1 ⌊ n i ⌋ μ ( j ) ⌊ n i j ⌋ ⌊ m i j ⌋ i ) − n m = \left( 2 \sum_{i=1}^n \sum_{j=1}^{\lfloor \frac{n}{i} \rfloor} \mu(j) \lfloor \frac{n}{ij} \rfloor \lfloor \frac{m}{ij} \rfloor i \right) - nm =2i=1nj=1inμ(j)ijnijminm

= ( 2 ∑ i = 1 n ⌊ n i ⌋ ⌊ m i ⌋ ∑ d ∣ i d μ ( i d ) ) − n m = \left( 2 \sum_{i=1}^n \lfloor \frac{n}{i} \rfloor \lfloor \frac{m}{i} \rfloor \sum_{d|i} d \mu(\dfrac{i}{d}) \right) - nm =2i=1ninimdidμ(di)nm

可以预处理 ∑ d ∣ i d μ ( i d ) \sum_{d|i} d \mu(\dfrac{i}{d}) didμ(di) 的前缀和


[SDOI2014]数表

∑ i = 1 n ∑ j = 1 m ∑ d ∣ gcd ⁡ ( i , j ) d [ ∑ d ∣ gcd ⁡ ( i , j ) d ≤ a ] \sum_{i=1}^n \sum_{j=1}^m \sum_{d|\gcd(i,j)} d [\sum_{d|\gcd(i,j)} d \leq a] i=1nj=1mdgcd(i,j)d[dgcd(i,j)da]

= ∑ i = 1 n σ 1 ( i ) [ σ 1 ( i ) ≤ a ] ∑ x = 1 ⌊ n i ⌋ ∑ y = 1 ⌊ m i ⌋ [ g c d ( x , y ) = 1 ] = \sum_{i=1}^n \sigma_1(i) [\sigma_1(i) \leq a] \sum_{x=1}^{\lfloor \frac{n}{i} \rfloor} \sum_{y=1}^{\lfloor \frac{m}{i} \rfloor} [gcd(x,y)=1] =i=1nσ1(i)[σ1(i)a]x=1iny=1im[gcd(x,y)=1]

= ∑ i = 1 n σ 1 ( i ) [ σ 1 ( i ) ≤ a ] ∑ x = 1 ⌊ n i ⌋ ∑ y = 1 ⌊ m i ⌋ ∑ d ∣ g c d ( x , y ) μ ( d ) = \sum_{i=1}^n \sigma_1(i) [\sigma_1(i) \leq a] \sum_{x=1}^{\lfloor \frac{n}{i} \rfloor} \sum_{y=1}^{\lfloor \frac{m}{i} \rfloor} \sum_{d|gcd(x,y)} \mu(d) =i=1nσ1(i)[σ1(i)a]x=1iny=1imdgcd(x,y)μ(d)

= ∑ i = 1 n σ 1 ( i ) [ σ 1 ( i ) ≤ a ] ∑ j = 1 ⌊ n i ⌋ μ ( j ) ⌊ n i j ⌋ ⌊ m i j ⌋ = \sum_{i=1}^n \sigma_1(i) [\sigma_1(i) \leq a] \sum_{j=1}^{\lfloor \frac{n}{i} \rfloor} \mu(j) \lfloor \frac{n}{ij} \rfloor \lfloor \frac{m}{ij} \rfloor =i=1nσ1(i)[σ1(i)a]j=1inμ(j)ijnijm

= ∑ i = 1 n ⌊ n i ⌋ ⌊ m i ⌋ ∑ d ∣ i μ ( i d ) σ 1 ( d ) [ σ 1 ( d ) ≤ a ] = \sum_{i=1}^n \lfloor \frac{n}{i} \rfloor \lfloor \frac{m}{i} \rfloor \sum_{d|i} \mu(\dfrac{i}{d}) \sigma_1(d)[\sigma_1(d) \leq a] =i=1ninimdiμ(di)σ1(d)[σ1(d)a]

离线预处理 ∑ d ∣ i μ ( i d ) σ 1 ( d ) [ σ 1 ( d ) ≤ a ] \sum_{d|i} \mu(\dfrac{i}{d}) \sigma_1(d)[\sigma_1(d) \leq a] diμ(di)σ1(d)[σ1(d)a] 即可


[SDOI2017]数字表格

∏ i = 1 n ∏ j = 1 m f [ gcd ⁡ ( i , j ) ] \prod_{i=1}^n \prod_{j=1}^m f[\gcd(i,j)] i=1nj=1mf[gcd(i,j)]

= ∏ i = 1 n f [ i ] ∑ x = 1 ⌊ n i ⌋ ∑ y = 1 ⌊ m i ⌋ [ g c d ( i , j ) = 1 ] =\prod_{i=1}^n f[i]^{\sum_{x=1}^{\lfloor \frac{n}{i} \rfloor} \sum_{y=1}^{\lfloor \frac{m}{i} \rfloor} [gcd(i,j)=1]} =i=1nf[i]x=1iny=1im[gcd(i,j)=1]

= ∏ i = 1 n f [ i ] ∑ j = 1 ⌊ n i ⌋ μ ( j ) ⌊ n i j ⌋ ⌊ m i j ⌋ =\prod_{i=1}^n f[i]^{\sum_{j=1}^{\lfloor \frac{n}{i} \rfloor} \mu(j) \lfloor \frac{n}{ij} \rfloor \lfloor \frac{m}{ij} \rfloor } =i=1nf[i]j=1inμ(j)ijnijm

= ∏ i = 1 n ∏ j = 1 ⌊ n i ⌋ f [ i ] μ ( j ) ⌊ n i j ⌋ ⌊ m i j ⌋ =\prod_{i=1}^n \prod_{j=1}^{\lfloor \frac{n}{i} \rfloor} f[i]^{\mu(j) \lfloor \frac{n}{ij} \rfloor \lfloor \frac{m}{ij} \rfloor} =i=1nj=1inf[i]μ(j)ijnijm

= ∏ i = 1 n ( ∏ d ∣ i f [ d ] μ ( i d ) ) ⌊ n i ⌋ ⌊ m i ⌋ =\prod_{i=1}^n (\prod_{d|i}f[d]^{\mu(\frac{i}{d})})^{\lfloor \frac{n}{i} \rfloor \lfloor \frac{m}{i} \rfloor} =i=1n(dif[d]μ(di))inim

预处理 ∏ d ∣ i f [ d ] μ ( i d ) \prod_{d|i}f[d]^{\mu(\frac{i}{d})} dif[d]μ(di) 的前缀积即可


[POI2007]ZAP-Queries

∑ i = 1 n ∑ j = 1 m [ gcd ⁡ ( i , j ) = d ] \sum_{i=1}^n \sum_{j=1}^m [\gcd(i,j)=d] i=1nj=1m[gcd(i,j)=d]

= ∑ i = 1 ⌊ n d ⌋ ∑ j = 1 ⌊ m d ⌋ [ gcd ⁡ ( i , j ) = 1 ] =\sum_{i=1}^{\lfloor \frac{n}{d} \rfloor} \sum_{j=1}^{\lfloor \frac{m}{d} \rfloor} [\gcd(i,j)=1] =i=1dnj=1dm[gcd(i,j)=1]

= ∑ i = 1 ⌊ n d ⌋ ∑ j = 1 ⌊ m d ⌋ ∑ k ∣ gcd ⁡ ( i , j ) μ ( k ) =\sum_{i=1}^{\lfloor \frac{n}{d} \rfloor} \sum_{j=1}^{\lfloor \frac{m}{d} \rfloor} \sum_{k|\gcd(i,j)} \mu(k) =i=1dnj=1dmkgcd(i,j)μ(k)

= ∑ i = 1 ⌊ n d ⌋ μ ( i ) ⌊ n d i ⌋ ⌊ m d i ⌋ =\sum_{i=1}^{\lfloor \frac{n}{d} \rfloor} \mu(i) \lfloor \frac{n}{di} \rfloor \lfloor \frac{m}{di} \rfloor =i=1dnμ(i)dindim


[HAOI2011]Problem b

∑ i = 1 b ∑ j = 1 d [ gcd ⁡ ( i , j ) = k ] − ∑ i = 1 a ∑ j = 1 d [ gcd ⁡ ( i , j ) = k ] − ∑ i = 1 b ∑ j = 1 c [ gcd ⁡ ( i , j ) = k ] + ∑ i = 1 a ∑ j = 1 c [ gcd ⁡ ( i , j ) = k ] \sum_{i=1}^b \sum_{j=1}^d [\gcd(i,j)=k] - \sum_{i=1}^a \sum_{j=1}^d [\gcd(i,j)=k] - \sum_{i=1}^b \sum_{j=1}^c [\gcd(i,j)=k] + \sum_{i=1}^a \sum_{j=1}^c [\gcd(i,j)=k] i=1bj=1d[gcd(i,j)=k]i=1aj=1d[gcd(i,j)=k]i=1bj=1c[gcd(i,j)=k]+i=1aj=1c[gcd(i,j)=k]

同上即可


[SDOI2015]约数个数和

∑ i = 1 n ∑ j = 1 m σ 0 ( i j ) \sum_{i=1}^n \sum_{j=1}^m \sigma_0(ij) i=1nj=1mσ0(ij)

= ∑ i = 1 n ∑ j = 1 m ∑ x ∣ i ∑ y ∣ j [ gcd ⁡ ( x , y ) = 1 ] =\sum_{i=1}^n \sum_{j=1}^m \sum_{x|i} \sum_{y|j} [\gcd(x,y)=1] =i=1nj=1mxiyj[gcd(x,y)=1]

= ∑ x = 1 n ∑ y = 1 m ∑ i = 1 ⌊ n x ⌋ ∑ j = 1 ⌊ m y ⌋ [ gcd ⁡ ( x , y ) = 1 ] =\sum_{x=1}^n \sum_{y=1}^m \sum_{i=1}^{\lfloor \frac{n}{x} \rfloor} \sum_{j=1}^{\lfloor \frac{m}{y} \rfloor} [\gcd(x,y)=1] =x=1ny=1mi=1xnj=1ym[gcd(x,y)=1]

= ∑ x = 1 n ∑ y = 1 m ⌊ n x ⌋ ⌊ m y ⌋ [ gcd ⁡ ( x , y ) = 1 ] =\sum_{x=1}^n \sum_{y=1}^m \lfloor \frac{n}{x} \rfloor \lfloor \frac{m}{y} \rfloor [\gcd(x,y)=1] =x=1ny=1mxnym[gcd(x,y)=1]

= ∑ x = 1 n ∑ y = 1 m ⌊ n x ⌋ ⌊ m y ⌋ ∑ d ∣ g c d ( x , y ) μ ( d ) =\sum_{x=1}^n \sum_{y=1}^m \lfloor \frac{n}{x} \rfloor \lfloor \frac{m}{y} \rfloor \sum_{d|gcd(x,y)} \mu(d) =x=1ny=1mxnymdgcd(x,y)μ(d)

= ∑ d = 1 n μ ( d ) ∑ x = 1 ⌊ n d ⌋ ⌊ n x d ⌋ ∑ y = 1 ⌊ m d ⌋ ⌊ m y d ⌋ =\sum_{d=1}^n \mu(d) \sum_{x=1}^{\lfloor \frac{n}{d} \rfloor} \lfloor \frac{n}{xd} \rfloor \sum_{y=1}^{\lfloor \frac{m}{d} \rfloor} \lfloor \frac{m}{yd} \rfloor =d=1nμ(d)x=1dnxdny=1dmydm

= ∑ d = 1 n μ ( d ) d i v s ( ⌊ n d ⌋ ) d i v s ( ⌊ m d ⌋ ) =\sum_{d=1}^n \mu(d) divs(\lfloor \frac{n}{d} \rfloor) divs(\lfloor \frac{m}{d} \rfloor) =d=1nμ(d)divs(dn)divs(dm)


[CQOI2015]选数

∑ x 1 = l h ∑ x 2 = l h ⋯ ∑ x n = l h [ gcd ⁡ ( x 1 , x 2 , ⋯   , x n ) = k ] \sum_{x_1=l}^h \sum_{x_2=l}^h \cdots \sum_{x_n=l}^h [\gcd(x_1,x_2,\cdots,x_n)=k] x1=lhx2=lhxn=lh[gcd(x1,x2,,xn)=k]

= ∑ x 1 = ⌈ l k ⌉ ⌊ h k ⌋ ∑ x 2 = ⌈ l k ⌉ ⌊ h k ⌋ ⋯ ∑ x n = ⌈ l k ⌉ ⌊ h k ⌋ ∑ d ∣ gcd ⁡ ( x 1 , x 2 , ⋯   , x n ) μ ( d ) =\sum_{x_1=\lceil \frac{l}{k} \rceil}^{\lfloor \frac{h}{k} \rfloor} \sum_{x_2=\lceil \frac{l}{k} \rceil}^{\lfloor \frac{h}{k} \rfloor} \cdots \sum_{x_n=\lceil \frac{l}{k} \rceil}^{\lfloor \frac{h}{k} \rfloor} \sum_{d|\gcd(x_1,x_2,\cdots,x_n)} \mu(d) =x1=klkhx2=klkhxn=klkhdgcd(x1,x2,,xn)μ(d)

= ∑ d = ⌈ l k ⌉ ⌊ h k ⌋ μ ( d ) ( ⌊ h k d ⌋ − ⌈ ⌈ l k ⌉ d ⌉ ) n =\sum_{d=\lceil \frac{l}{k} \rceil}^{\lfloor \frac{h}{k} \rfloor} \mu(d) (\lfloor \frac{h}{kd} \rfloor - \lceil \frac{\lceil \frac{l}{k} \rceil}{d} \rceil)^n =d=klkhμ(d)(kdhdkl)n


常见积性函数与迪利克雷卷积(用于杜教筛)

ϵ ( i ) = [ i = 1 ] \epsilon(i)=[i=1] ϵ(i)=[i=1]

I ( i ) = 1 \text{I}(i)=1 I(i)=1

id ( i ) = i \text{id}(i)=i id(i)=i

μ ∗ I = ϵ \mu * \text{I} =\epsilon μI=ϵ

μ ∗ id = φ \mu * \text{id} =\varphi μid=φ

φ ∗ I = id \varphi * \text{I} = \text{id} φI=id


简单的数学题

∑ i = 1 n ∑ j = 1 n i j gcd ⁡ ( i , j ) \sum_{i=1}^n \sum_{j=1}^n ij\gcd(i,j) i=1nj=1nijgcd(i,j)

= ∑ i = 1 n ∑ x = 1 ⌊ n i ⌋ ∑ y = 1 ⌊ n i ⌋ x y i 3 [ gcd ⁡ ( x , y ) = = 1 ] =\sum_{i=1}^n \sum_{x=1}^{\lfloor \frac{n}{i} \rfloor} \sum_{y=1}^{\lfloor \frac{n}{i} \rfloor}xyi^3[\gcd(x,y)==1] =i=1nx=1iny=1inxyi3[gcd(x,y)==1]

= ∑ i = 1 n ∑ x = 1 ⌊ n i ⌋ ∑ y = 1 ⌊ n i ⌋ x y i 3 ∑ d ∣ gcd ⁡ ( x , y ) μ ( d ) =\sum_{i=1}^n \sum_{x=1}^{\lfloor \frac{n}{i} \rfloor} \sum_{y=1}^{\lfloor \frac{n}{i} \rfloor}xyi^3 \sum_{d|\gcd(x,y)} \mu(d) =i=1nx=1iny=1inxyi3dgcd(x,y)μ(d)

= ∑ i = 1 n i 3 ∑ j = 1 ⌊ n i ⌋ j 2 μ ( j ) ∑ x = 1 ⌊ n i j ⌋ x ∑ y = 1 ⌊ n i j ⌋ y =\sum_{i=1}^n i^3 \sum_{j=1}^{\lfloor \frac{n}{i} \rfloor} j^2 \mu(j) \sum_{x=1}^{\lfloor \frac{n}{ij} \rfloor} x \sum_{y=1}^{\lfloor \frac{n}{ij} \rfloor} y =i=1ni3j=1inj2μ(j)x=1ijnxy=1ijny

= ∑ i = 1 n i 3 ∑ j = 1 ⌊ n i ⌋ j 2 μ ( j ) ( ⌊ n i j ⌋ ) 2 ( ⌊ n i j ⌋ + 1 ) 2 4 =\sum_{i=1}^n i^3 \sum_{j=1}^{\lfloor \frac{n}{i} \rfloor} j^2 \mu(j) \frac{(\lfloor \frac{n}{ij} \rfloor)^2(\lfloor \frac{n}{ij} \rfloor + 1)^2}{4} =i=1ni3j=1inj2μ(j)4(ijn)2(ijn+1)2

= ∑ i = 1 n i 2 ( ⌊ n i ⌋ ) 2 ( ⌊ n i ⌋ + 1 ) 2 4 ∑ d ∣ i d μ ( i d ) =\sum_{i=1}^n i^2 \frac{(\lfloor \frac{n}{i} \rfloor)^2(\lfloor \frac{n}{i} \rfloor + 1)^2}{4} \sum_{d|i} d \mu(\frac{i}{d}) =i=1ni24(in)2(in+1)2didμ(di)

= ∑ i = 1 n i 2 φ ( i ) ( ⌊ n i ⌋ ) 2 ( ⌊ n i ⌋ + 1 ) 2 4 =\sum_{i=1}^n i^2 \varphi(i)\frac{(\lfloor \frac{n}{i} \rfloor)^2(\lfloor \frac{n}{i} \rfloor + 1)^2}{4} =i=1ni2φ(i)4(in)2(in+1)2

杜教筛 i 2 φ ( i ) i^2 \varphi(i) i2φ(i) 前缀和,整除分块

如何杜教筛 i 2 φ ( i ) i^2 \varphi(i) i2φ(i)

f ( i ) = i 2 φ ( i ) f(i)=i^2 \varphi(i) f(i)=i2φ(i)

g ( i ) = id ( i 2 ) g(i)=\text{id}(i^2) g(i)=id(i2)

( f ∗ g ) ( i ) = ∑ d ∣ i ( d 2 φ ( d ) ) ( i d ) 2 = i 2 ∑ d ∣ i φ ( d ) = i 3 (f * g)(i)= \sum_{d|i} (d^2 \varphi(d))(\frac{i}{d})^2 = i^2 \sum_{d|i} \varphi(d) = i^3 (fg)(i)=di(d2φ(d))(di)2=i2diφ(d)=i3

你可能感兴趣的:(OI)