【技能点】莫比乌斯反演

莫比乌斯反演公式:
正向情况下:
f ( n ) = ∑ d ∣ n g ( d ) f(n)=\sum_{d|n}g(d) f(n)=dng(d)
g ( n ) = ∑ d ∣ n μ ( n d ) f ( d ) g(n)=\sum_{d|n}\mu(\frac{n}{d})f(d) g(n)=dnμ(dn)f(d)
反向情况下:
f ( n ) = ∑ n ∣ d g ( d ) f(n)=\sum_{n|d}g(d) f(n)=ndg(d)
g ( n ) = ∑ n ∣ d μ ( d n ) f ( d ) g(n)=\sum_{n|d}\mu(\frac{d}{n})f(d) g(n)=ndμ(nd)f(d)
另有:
∑ d ∣ n μ ( d ) = [ n = 1 ] \sum_{d|n}\mu(d)=[n=1] dnμ(d)=[n=1]

积性函数的狄利克雷卷积也是积性函数。
常用狄利克雷卷积:
∑ d ∣ n φ ( d ) = n \sum_{d|n}\varphi(d)=n dnφ(d)=n
∑ d ∣ n μ ( d ) n d = φ ( n ) \sum_{d|n}\mu(d)\frac{n}{d}=\varphi(n) dnμ(d)dn=φ(n)

注意,非积性函数一样可以反演。

例题:

1.计算 ∑ i = 1 n ∑ j = 1 m g c d ( i , j ) \sum_{i=1}^{n}\sum_{j=1}^{m}gcd(i,j) i=1nj=1mgcd(i,j)

f ( n ) = n = ∑ d ∣ n f r ( d ) f(n)=n=\sum_{d|n}fr(d) f(n)=n=dnfr(d)
所以 f r ( n ) = ∑ d ∣ n μ ( n d ) d = φ ( n ) fr(n)=\sum_{d|n}\mu(\frac{n}{d})d=\varphi(n) fr(n)=dnμ(dn)d=φ(n)
g c d ( i , j ) gcd(i,j) gcd(i,j)代入 f ( n ) f(n) f(n)中得 f ( g c d ( i , j ) ) = g c d ( i , j ) = ∑ d = 1 [ d ∣ i ] [ d ∣ j ] φ ( d ) f(gcd(i,j))=gcd(i,j)=\sum_{d=1}[d|i][d|j]\varphi(d) f(gcd(i,j))=gcd(i,j)=d=1[di][dj]φ(d)
代回原公式得
∑ i = 1 n ∑ j = 1 m g c d ( i , j ) = ∑ i = 1 n ∑ j = 1 m ∑ d = 1 m i n ( n , m ) [ d ∣ i ] [ d ∣ j ] φ ( d ) \sum_{i=1}^{n}\sum_{j=1}^{m}gcd(i,j) =\sum_{i=1}^{n}\sum_{j=1}^{m}\sum_{d=1}^{min(n,m)}[d|i][d|j]\varphi(d) i=1nj=1mgcd(i,j)=i=1nj=1md=1min(n,m)[di][dj]φ(d)
交换和式位置得
原 式 = ∑ d = 1 m i n ( n , m ) ∑ i = 1 n ∑ j = 1 m [ d ∣ i ] [ d ∣ j ] φ ( d ) = ∑ d = 1 m i n ( n , m ) ∑ d ∣ i n ∑ d ∣ j m φ ( d ) = ∑ d = 1 m i n ( n , m ) φ ( d ) ∑ d ∣ i n 1 ∑ d ∣ j m 1 原式=\sum_{d=1}^{min(n,m)}\sum_{i=1}^{n}\sum_{j=1}^{m}[d|i][d|j]\varphi(d)=\sum_{d=1}^{min(n,m)}\sum_{d|i}^{n}\sum_{d|j}^{m}\varphi(d)=\sum_{d=1}^{min(n,m)}\varphi(d)\sum_{d|i}^{n}1\sum_{d|j}^{m}1 =d=1min(n,m)i=1nj=1m[di][dj]φ(d)=d=1min(n,m)dindjmφ(d)=d=1min(n,m)φ(d)din1djm1
化简后面两个和式得
原 式 = ∑ d = 1 m i n ( n , m ) φ ( d ) ⌊ n d ⌋ ⌊ m d ⌋ 原式= \sum_{d=1}^{min(n,m)}\varphi(d)\lfloor \frac{n}{d} \rfloor\lfloor \frac{m}{d} \rfloor =d=1min(n,m)φ(d)dndm
2.计算 ∑ i = 1 n ∑ j = 1 m [ g c d ( i , j ) = t ] \sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)=t] i=1nj=1m[gcd(i,j)=t]
∑ d ∣ n μ ( d ) = [ n = 1 ] \sum_{d|n}\mu(d)=[n=1] dnμ(d)=[n=1]代入得
原 式 = ∑ i = 1 n ∑ j = 1 m ∑ d = 1 m i n ( n , m ) [ t ∣ i ] [ t ∣ j ] [ d ∣ i t ] [ d ∣ j t ] μ ( d ) = ∑ d = 1 m i n ( n , m ) ∑ i = 1 ⌊ n t ⌋ ∑ j = 1 ⌊ m t ⌋ [ d ∣ i ] [ d ∣ j ] μ ( d ) 原式=\sum_{i=1}^{n}\sum_{j=1}^{m}\sum_{d=1}^{min(n,m)}[t|i][t|j][d|\frac{i}{t}][d|\frac{j}{t}]\mu(d)=\sum_{d=1}^{min(n,m)}\sum_{i=1}^{\lfloor \frac{n}{t} \rfloor}\sum_{j=1}^{\lfloor \frac{m}{t} \rfloor}[d|i][d|j]\mu(d) =i=1nj=1md=1min(n,m)[ti][tj][dti][dtj]μ(d)=d=1min(n,m)i=1tnj=1tm[di][dj]μ(d)
原 式 = ∑ d = 1 m i n ( n , m ) μ ( d ) ⌊ n t d ⌋ ⌊ m t d ⌋ 原式=\sum_{d=1}^{min(n,m)}\mu(d) \lfloor\frac{n}{td}\rfloor \lfloor \frac{m}{td} \rfloor =d=1min(n,m)μ(d)tdntdm

奇怪的代换:
∑ j = 1 i − 1 j [ g c d ( i , j ) = 1 ] = n ϕ ( n ) + [ n = 1 ] 2 \sum_{j=1}^{i-1}j[gcd(i,j)=1]=\frac{n\phi(n)+[n=1]}{2} j=1i1j[gcd(i,j)=1]=2nϕ(n)+[n=1]
证明 对于每一个与 n n n互质的 i i i,那么 n − i n-i ni也一定与 n n n互质。原因考虑更相减损。

你可能感兴趣的:(技能点,莫比乌斯反演)