也许更好的阅读体验
③等价于
∀ n : ∑ d ∣ n f ( d ) ⋅ f − 1 ( n d ) = [ n = 1 ] \begin{aligned}\forall n: \sum_{d|n} f(d)·f^{-1}(\frac nd)=[n=1]\end{aligned} ∀n:d∣n∑f(d)⋅f−1(dn)=[n=1]
∑ d ∣ n f ( d ) ⋅ f − 1 ( n d ) = I ( n ) ( n = ̸ 1 ) = 0 \begin{aligned}\sum_{d|n}f(d)·f^{-1}(\frac nd)=I(n) (n=\not 1)=0\end{aligned} d∣n∑f(d)⋅f−1(dn)=I(n)(n≠1)=0
f − 1 ( n ) ⋅ f ( 1 ) = − ∑ d ∣ n , d = ̸ 1 f ( d ) ⋅ f − 1 ( n d ) f^{-1}(n)·f(1)=-\sum_{d|n,d=\not1}f(d)·f^{-1}(\frac nd) f−1(n)⋅f(1)=−∑d∣n,d≠1f(d)⋅f−1(dn)
f − 1 ( n ) = − ∑ d ∣ n , d = ̸ 1 f ( d ) ⋅ f − 1 ( n d ) f ( 1 ) \begin{aligned}f^{-1}(n)=\frac{-\sum_{d|n,d=\not1}f(d)·f^{-1}(\frac nd)}{f(1)}\end{aligned} f−1(n)=f(1)−∑d∣n,d≠1f(d)⋅f−1(dn)
令 f = ξ f=\xi f=ξ, p p p为质数
f − 1 ( 1 ) = 1 f^{-1}(1)=1 f−1(1)=1
f − 1 ( p ) = − f ( p ) ⋅ f − 1 ( 1 ) f ( 1 ) = − 1 f^{-1}(p)=\frac{-f(p)·f^{-1}(1)}{f(1)}=-1 f−1(p)=f(1)−f(p)⋅f−1(1)=−1
f − 1 ( p 2 ) = − ( f ( p 2 ) ⋅ f − 1 ( 1 ) + f ( p ) ⋅ f − 1 ( p ) ) = 0 f^{-1}(p^2)=-(f(p^2)·f^{-1}(1)+f(p)·f^{-1}(p))=0 f−1(p2)=−(f(p2)⋅f−1(1)+f(p)⋅f−1(p))=0
f − 1 ( p 3 ) = − ( f ( p 3 ) ⋅ f − 1 ( 1 ) + f ( p 2 ) ⋅ f − 1 ( p ) + f ( p ) ⋅ f − 1 ( p 2 ) ) = 0 f^{-1}(p^3)=-(f(p^3)·f^{-1}(1)+f(p^2)·f^{-1}(p)+f(p)·f^{-1}(p^2))=0 f−1(p3)=−(f(p3)⋅f−1(1)+f(p2)⋅f−1(p)+f(p)⋅f−1(p2))=0
f − 1 ( p k ) = − ∑ i = 1 k f ( p i ) ⋅ f − 1 ( p k − i ) \begin{aligned}f^{-1}(p^k)=-\sum_{i=1}^k f(p^i)·f^{-1}(p^{k-i})\end{aligned} f−1(pk)=−i=1∑kf(pi)⋅f−1(pk−i)
其中只有 f ( p k ) ⋅ f − 1 ( 1 ) = 1 , f ( p k − 1 ) ⋅ f − 1 ( p ) = − 1 f(p^k)·f^{-1}(1)=1,f(p^{k-1})·f^{-1}(p)=-1 f(pk)⋅f−1(1)=1,f(pk−1)⋅f−1(p)=−1,其余项都是0
f − 1 ( p k ) = { − 1 k = 1 0 k > 1 f^{-1}(p^k)=\left\{\begin{matrix}-1 & k=1\\0 & k>1 \end{matrix}\right. f−1(pk)={−10k=1k>1
n = p 1 a 1 ⋅ p 2 a 2 ⋅ ⋯ p k a k n=p_1^{a_1}·p_2^{a_2}·\cdots p_k^{a_k} n=p1a1⋅p2a2⋅⋯pkak
所以莫比乌斯函数可以推出来了
μ ( n ) = f − 1 ( n ) = { 1 n = 1 ( − 1 ) k a 1 = a 2 = ⋯ = a k = 1 ⇐ 积 性 函 数 推 出 0 o t h e r w i s e \mu(n)=f^{-1}(n)= \left\{\begin{matrix}1 &n=1 \\(-1)^k &a1=a2=\cdots =ak=1&\Leftarrow 积性函数推出 \\ 0&otherwise \end{matrix}\right. μ(n)=f−1(n)=⎩⎨⎧1(−1)k0n=1a1=a2=⋯=ak=1otherwise⇐积性函数推出
利用积性函数的性质以及 μ \mu μ的表达式
int cnt;
int prime[maxn],mu[maxn];
bool vis[maxn];
void mu_sieve (int n)
{
mu[1]=1;
for (int i=2;i<=n;++i){
if (!vis[i]){ prime[++cnt]=i,mu[i]=-1;}
for (int j=1;j<=cnt&&i*prime[j]<=n;++j){
vis[i*prime[j]]=true;
if (i%prime[j]==0){
mu[i*prime[j]]=0;
break;
}
mu[i*prime[j]]=-mu[i];
}
}
}
若有 g ( n ) = ∑ d ∣ n f ( d ) \begin{aligned}g(n)=\sum_{d|n}f(d)\end{aligned} g(n)=d∣n∑f(d)
则有 f ( n ) = ∑ d ∣ n μ ( d ) g ( n d ) = ∑ d ∣ n μ ( n d ) g ( d ) \begin{aligned}f(n)=\sum_{d|n}\mu(d)g(\frac{n}{d})=\sum_{d|n}\mu(\frac{n}{d})g(d)\end{aligned} f(n)=d∣n∑μ(d)g(dn)=d∣n∑μ(dn)g(d)
若有 g ( n ) = ∑ n ∣ d f ( d ) \begin{aligned}g(n)=\sum_{n|d}f(d)\end{aligned} g(n)=n∣d∑f(d)
则有 f ( n ) = ∑ n ∣ d μ ( d n ) g ( d ) \begin{aligned}f(n)=\sum_{n|d}\mu(\frac{d}{n})g(d)\end{aligned} f(n)=n∣d∑μ(nd)g(d)
这一种一般用的比较多
莫比乌斯函数一般用于 g c d gcd gcd中
∑ i = 1 n ∑ j = 1 m gcd ( i , j ) = ∑ d m i n ( n , m ) d ∑ i = 1 n ∑ j = 1 m [ g c d ( i , j ) = d ] = ∑ d m i n ( n , m ) d ∑ i = 1 n d ∑ j = 1 m d [ g c d ( i , j ) = 1 ] = ∑ d m i n ( n , m ) d ∑ i = 1 n d ∑ j = 1 m d ∑ k ∣ g c d ( i , j ) μ ( k ) = ∑ d m i n ( n , m ) d ∑ k m i n ( n d , m d ) μ ( k ) ∑ k ∣ i n d ∑ k ∣ j m d = ∑ d m i n ( n , m ) d ∑ k m i n ( n d , m d ) μ ( k ) ⌊ n k d ⌋ ⌊ m k d ⌋ \begin{aligned} \sum_{i=1}^n\sum_{j=1}^m\gcd(i,j)&=\sum_d^{min(n,m)} d\sum_{i=1}^n\sum_{j=1}^m[gcd(i,j)=d] \\ &=\sum_{d}^{min(n,m)}d\sum_{i=1}^{\frac nd}\sum_{j=1}^{\frac md}[gcd(i,j)=1] \\ &=\sum_{d}^{min(n,m)}d\sum_{i=1}^{\frac nd}\sum_{j=1}^{\frac md}\sum_{k\mid gcd(i,j)}\mu(k) \\ &=\sum_d^{min(n,m)} d\sum_k^{min(\frac{n}{d},\frac{m}{d})}\mu(k)\sum_{k\mid i}^{\frac nd}\sum_{k\mid j}^{\frac md} \\ &=\sum_{d}^{min(n,m)}d\sum_k^{min(\frac{n}{d},\frac{m}{d})}\mu(k)\lfloor \frac n{kd}\rfloor \lfloor\frac m{kd}\rfloor \end{aligned} i=1∑nj=1∑mgcd(i,j)=d∑min(n,m)di=1∑nj=1∑m[gcd(i,j)=d]=d∑min(n,m)di=1∑dnj=1∑dm[gcd(i,j)=1]=d∑min(n,m)di=1∑dnj=1∑dmk∣gcd(i,j)∑μ(k)=d∑min(n,m)dk∑min(dn,dm)μ(k)k∣i∑dnk∣j∑dm=d∑min(n,m)dk∑min(dn,dm)μ(k)⌊kdn⌋⌊kdm⌋
令 T = k d T=kd T=kd
= ∑ T m i n ( n , m ) ⌊ n T ⌋ ⌊ m T ⌋ ∑ k ∣ T T k μ ( k ) \begin{aligned} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ =\sum_{T}^{min(n,m)}\lfloor\frac nT\rfloor\lfloor\frac mT\rfloor\sum_{k\mid T}\frac Tk\mu(k)\end{aligned} =T∑min(n,m)⌊Tn⌋⌊Tm⌋k∣T∑kTμ(k)
以上是莫比乌斯反演推出来的式子
= ∑ T m i n ( n , m ) ⌊ n T ⌋ ⌊ m T ⌋ φ ( T ) \begin{aligned}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ =\sum_{T}^{min(n,m)}\lfloor\frac nT\rfloor\lfloor\frac mT\rfloor\varphi(T)\end{aligned} =T∑min(n,m)⌊Tn⌋⌊Tm⌋φ(T)
这一步是欧拉反演,证明请移步欧拉函数|(扩展)欧拉定理|欧拉反演
当然,这里这个例子不如直接用欧拉反演
∑ i = 1 n ∑ j = 1 m gcd ( i , j ) = ∑ i = 1 n ∑ j = 1 m ∑ d ∣ g c d ( i , j ) φ ( d ) = ∑ d = 1 m i n ( n , m ) ⌊ n d ⌋ ⌊ m d ⌋ φ ( d ) \begin{aligned}\sum_{i=1}^n\sum_{j=1}^m\gcd(i,j)&=\sum_{i=1}^n\sum_{j=1}^m\sum_{d|gcd(i,j)}\varphi(d)=\sum_{d=1}^{min(n,m)}\lfloor\frac{n}{d}\rfloor\lfloor\frac{m}{d}\rfloor\varphi(d)\end{aligned} i=1∑nj=1∑mgcd(i,j)=i=1∑nj=1∑md∣gcd(i,j)∑φ(d)=d=1∑min(n,m)⌊dn⌋⌊dm⌋φ(d)
如有哪里讲得不是很明白或是有错误,欢迎指正
如您喜欢的话不妨点个赞收藏一下吧