# 反演定理及其应用

## 一、莫比乌斯反演

F(n)=i|nf(i) F ( n ) = ∑ i | n f ( i )

f(n)=i|nμ(i)F(ni) f ( n ) = ∑ i | n μ ( i ) F ( n i )

i|nμ(i)j|nif(i)=j|nf(j)i|njμ(i)=j|nf(j)[nj=1]=f(n) ∑ i | n μ ( i ) ∑ j | n i f ( i ) = ∑ j | n f ( j ) ∑ i | n j μ ( i ) = ∑ j | n f ( j ) [ n j = 1 ] = f ( n )

F(n)=n|if(i) F ( n ) = ∑ n | i f ( i )

f(n)=n|iμ(in)F(i) f ( n ) = ∑ n | i μ ( i n ) F ( i )

#### 例题：BZOJ1101

f(k)=i=1nj=1m[gcd(i,j)=k] f ( k ) = ∑ i = 1 n ∑ j = 1 m [ g c d ( i , j ) = k ]
F(k)=k|if(i)=i=1nj=1m[k|gcd(i,j)]=nkmk F ( k ) = ∑ k | i f ( i ) = ∑ i = 1 n ∑ j = 1 m [ k | g c d ( i , j ) ] = ⌊ n k ⌋ ⌊ m k ⌋

f(k)=k|iμ(ik)F(i)=k|iμ(ik)nimi=i=1n/kμ(i)nkimki f ( k ) = ∑ k | i μ ( i k ) F ( i ) = ∑ k | i μ ( i k ) ⌊ n i ⌋ ⌊ m i ⌋ = ∑ i = 1 n / k μ ( i ) ⌊ n k i ⌋ ⌊ m k i ⌋

## 二、二项式反演

F(n)=i=pn(ni)f(i) F ( n ) = ∑ i = p n ( n i ) f ( i )

f(n)=i=pn(1)ni(ni)F(i) f ( n ) = ∑ i = p n ( − 1 ) n − i ( n i ) F ( i )

i=pn(1)ni(ni)F(i)=i=pn(1)ni(ni)j=pn(ij)f(j)=j=pnf(j)i=jn(1)ni(ni)(ij)=j=pnf(j)(nj)i=jn(1)ni(njij)=j=pnf(j)(nj)i=0nj(1)nji(nji)=j=pnf(j)(nj)0nj ∑ i = p n ( − 1 ) n − i ( n i ) F ( i ) = ∑ i = p n ( − 1 ) n − i ( n i ) ∑ j = p n ( i j ) f ( j ) = ∑ j = p n f ( j ) ∑ i = j n ( − 1 ) n − i ( n i ) ( i j ) = ∑ j = p n f ( j ) ( n j ) ∑ i = j n ( − 1 ) n − i ( n − j i − j ) = ∑ j = p n f ( j ) ( n j ) ∑ i = 0 n − j ( − 1 ) n − j − i ( n − j i ) = ∑ j = p n f ( j ) ( n j ) · 0 n − j

j=pnf(j)(nj)0nj=f(n) ∑ j = p n f ( j ) ( n j ) · 0 n − j = f ( n )

g(m)=i=mn(im)f(i) g ( m ) = ∑ i = m n ( i m ) f ( i )
f(m)=i=mn(1)im(im)g(i) f ( m ) = ∑ i = m n ( − 1 ) i − m ( i m ) g ( i )

#### 例题

##### 染色问题

g(m)=i=2m(mi)f(i) g ( m ) = ∑ i = 2 m ( m i ) f ( i )

f(m)=i=2m(1)mi(mi)g(i)=i=2m(1)mi(mi)i(i1)n1 f ( m ) = ∑ i = 2 m ( − 1 ) m − i ( m i ) g ( i ) = ∑ i = 2 m ( − 1 ) m − i ( m i ) i ( i − 1 ) n − 1

##### 洛谷8月月赛T4

(nm2,000(mn10nm100,000)) ( n ≤ m ≤ 2 , 000 或 ( m − n ≤ 10 且 n ≤ m ≤ 100 , 000 ) ) $(n\le m\le 2,000或(m-n\le 10 且 n\le m\le 100,000))$

$f\left(n,m\right)为原题答案，g\left(n,m\right)$$f(n,m)为原题答案，g(n,m)$为满足上述条件的方案数。考虑如何求 g(n,m) g ( n , m ) $g(n,m)$

g(n,m)=i=0m(mi)A2i2n2iA2n2imi g ( n , m ) = ∑ i = 0 m ( m i ) A 2 n 2 i 2 i A m − i 2 n − 2 i

g(n,m)=i=max(2nm,0)n(mi)A2i2n2iA2n2imi g ( n , m ) = ∑ i = m a x ( 2 n − m , 0 ) n ( m i ) A 2 n 2 i 2 i A m − i 2 n − 2 i

g(n,m)=i=0n(ni)Aim2nif(ni,mi) g ( n , m ) = ∑ i = 0 n ( n i ) A m i 2 n − i f ( n − i , m − i )

g(n,m)m!=i=0n(ni)2nif(ni,mi)i! g ( n , m ) m ! = ∑ i = 0 n ( n i ) 2 n − i f ( n − i , m − i ) i !

F(i)=2if(i,in+m)(in+m)!G(i)=g(i,in+m)(in+m)! F ( i ) = 2 i f ( i , i − n + m ) ( i − n + m ) ! ， G ( i ) = g ( i , i − n + m ) ( i − n + m ) !

G(n)=i=0n(ni)F(ni)=i=0n(ni)F(i) G ( n ) = ∑ i = 0 n ( n i ) F ( n − i ) = ∑ i = 0 n ( n i ) F ( i )

F(n)=i=0n(1)ni(ni)G(i) F ( n ) = ∑ i = 0 n ( − 1 ) n − i ( n i ) G ( i )

f(n,m)=m!2ni=0n(1)i(ni)g(ni,mi)(mi)! f ( n , m ) = m ! 2 n ∑ i = 0 n ( − 1 ) i ( n i ) g ( n − i , m − i ) ( m − i ) !

## 三、斯特林反演

#### 第一类斯特林数

xn=i=xn+1xi=i=0n(1)nis(n,i)xi x n _ = ∏ i = x − n + 1 x i = ∑ i = 0 n ( − 1 ) n − i s ( n , i ) x i

xn¯¯¯=i=xx+n1i=i=0ns(n,i)xi x n ¯ = ∏ i = x x + n − 1 i = ∑ i = 0 n s ( n , i ) x i

s(n,k)=s(n1,k1)+(n1)s(n1,k) s ( n , k ) = s ( n − 1 , k − 1 ) + ( n − 1 ) s ( n − 1 , k )

i=0ns(n,i)=n! ∑ i = 0 n s ( n , i ) = n !

#### 第二类斯特林数

S(n,k)=S(n1,k1)+kS(n1,k) S ( n , k ) = S ( n − 1 , k − 1 ) + k S ( n − 1 , k )

kn=i=1k(ki)S(n,i)i! k n = ∑ i = 1 k ( k i ) S ( n , i ) i !

S(n,k)=1k!i=1k(1)ki(ki)in=i=0k(1)ki(ki)!ini! S ( n , k ) = 1 k ! ∑ i = 1 k ( − 1 ) k − i ( k i ) i n = ∑ i = 0 k ( − 1 ) k − i ( k − i ) ! · i n i !

kn=i=1n(ki)S(n,i)i! k n = ∑ i = 1 n ( k i ) S ( n , i ) i !

i=mn(im)=(n+1nm)b<0b>a(ab)=0 ∑ i = m n ( i m ) = ( n + 1 n − m ) （ 边 界 条 件 定 义 ： 若 b < 0 或 b > a 则 ( a b ) = 0 ）

i=m+1n+1(im+1)=i=mn(im+1)+(im)=(n+1nm)+(n+1nm1)=(n+2(n+1)(m+1)) ∑ i = m + 1 n + 1 ( i m + 1 ) = ∑ i = m n ( i m + 1 ) + ( i m ) = ( n + 1 n − m ) + ( n + 1 n − m − 1 ) = ( n + 2 ( n + 1 ) − ( m + 1 ) )

i=1nik=i=1nj=1min(i,k)(ij)S(k,j)j!=j=1kS(k,j)j!i=jn(ij)=j=1kS(k,j)j!(n+1nj)=j=1kS(k,j)(n+1)j+1j+1 ∑ i = 1 n i k = ∑ i = 1 n ∑ j = 1 m i n ( i , k ) ( i j ) S ( k , j ) j ! = ∑ j = 1 k S ( k , j ) j ! ∑ i = j n ( i j ) = ∑ j = 1 k S ( k , j ) j ! ( n + 1 n − j ) = ∑ j = 1 k S ( k , j ) ( n + 1 ) j + 1 _ j + 1

#### 性质应用例题BZOJ2159

i=1ndist(u,i)k=i=1nj=1kS(k,j)(dist(u,i)j)j!=j=1kS(k,j)j!i=1n(dist(u,i)j) ∑ i = 1 n d i s t ( u , i ) k = ∑ i = 1 n ∑ j = 1 k S ( k , j ) ( d i s t ( u , i ) j ) j ! = ∑ j = 1 k S ( k , j ) j ! ∑ i = 1 n ( d i s t ( u , i ) j )

### 反演公式

g(n)=i=mnS(n,i)f(i) g ( n ) = ∑ i = m n S ( n , i ) f ( i )

f(n)=i=mn(1)nis(n,i)g(i) f ( n ) = ∑ i = m n ( − 1 ) n − i s ( n , i ) g ( i )

i=mn(1)nis(n,i)g(i) ∑ i = m n ( − 1 ) n − i s ( n , i ) g ( i )

=i=mn(1)nis(n,i)j=miS(i,j)f(j) = ∑ i = m n ( − 1 ) n − i s ( n , i ) ∑ j = m i S ( i , j ) f ( j )

=j=mnf(j)i=jn(1)nis(n,i)S(i,j) = ∑ j = m n f ( j ) ∑ i = j n ( − 1 ) n − i s ( n , i ) S ( i , j )

xn=i=1n(1)nis(n,i)xi=i=1n(1)nis(n,i)j=1iS(i,j)xj x n _ = ∑ i = 1 n ( − 1 ) n − i s ( n , i ) x i = ∑ i = 1 n ( − 1 ) n − i s ( n , i ) ∑ j = 1 i S ( i , j ) x j _

=j=1nxji=jn(1)nis(n,i)S(i,j) = ∑ j = 1 n x j _ ∑ i = j n ( − 1 ) n − i s ( n , i ) S ( i , j )

i=mn(1)nis(n,i)g(i)=f(n) ∑ i = m n ( − 1 ) n − i s ( n , i ) g ( i ) = f ( n )

g(m)=i=mnS(i,m)f(i)f(m)=i=mn(1)ims(i,m)g(i) g ( m ) = ∑ i = m n S ( i , m ) f ( i ) ， 则 f ( m ) = ∑ i = m n ( − 1 ) i − m s ( i , m ) g ( i )

i=mn(1)ims(i,m)g(i)=j=mnf(j)i=mj(1)imS(j,i)s(i,m) ∑ i = m n ( − 1 ) i − m s ( i , m ) g ( i ) = ∑ j = m n f ( j ) ∑ i = m j ( − 1 ) i − m S ( j , i ) s ( i , m )

xn=i=1nS(n,i)xi=i=1nS(n,i)j=1i(1)ijs(i,j)xj x n = ∑ i = 1 n S ( n , i ) x i _ = ∑ i = 1 n S ( n , i ) ∑ j = 1 i ( − 1 ) i − j s ( i , j ) x j

=j=1nxji=jn(1)ijS(n,i)s(i,j) = ∑ j = 1 n x j ∑ i = j n ( − 1 ) i − j S ( n , i ) s ( i , j )

j=mnf(j)i=mj(1)imS(j,i)s(i,m)=f(m) ∑ j = m n f ( j ) ∑ i = m j ( − 1 ) i − m S ( j , i ) s ( i , m ) = f ( m )

#### 例题BZOJ4617

g(m)=i=mnS(i,m)f(i) g ( m ) = ∑ i = m n S ( i , m ) f ( i )

f(m)=i=mn(1)ims(i,m)g(i) f ( m ) = ∑ i = m n ( − 1 ) i − m s ( i , m ) g ( i )

04-29 6864
07-29 1106

01-26 8887
08-16 2182
08-07 752
06-29 1106
05-29 1万+
02-25 5176
02-05 211
09-28 240
07-31 2451
03-13 354
06-01 2459
08-30 1951
09-19 571
06-02 261