对于定义在(mathbb{N})上的函数(F(n))和(f(n)),若满足:
(F(n) = sumlimits_{dmid n}f(d))
则有:
(f(n) = sumlimits_{dmid n}mu(d)F(frac{n}{d}))
一个更常用的形式是:
若有:
(F(n) = sumlimits_{nmid d}f(d))
则有:
(f(n) = sumlimits_{nmid d}mu(frac{d}{n})F(d))
其中(mu(d))为莫比乌斯函数:
令 (x = p_{1}^{a_{1}}p_{2}^{a_{2}}p_{3}^{a_{3}}cdotcdotcdot p_{k-1}^{a_{k-1}}p_{k}^{a_{k}},p_{1},p_{2},p_{3} cdot cdot cdot p_{k-1},p_{k}in mathbb{P})
则满足:
(mu(x) = left{egin{matrix}&1 &,x = 1\ &(-1)^{k} &,forall iin [1,k],a_{i}=1\ &0 &,exists iin [1,k],a_{i}>1end{matrix} ight.)
证明如下:
(sumlimits_{dmid n}mu(d)F(frac{n}{d}) = sumlimits_{dmid n}mu(d)sumlimits_{d^{'}midfrac{n}{d}}f(d^{'}) = sumlimits_{dmid n}sumlimits_{d^{'}midfrac{n}{d}}mu(d)f(d^{'}) = sumlimits_{d^{'}mid n}sumlimits_{dmidfrac{n}{d^{'}}}mu(d)f(d^{'}) = sumlimits_{d^{'}mid n}f(d^{'})sumlimits_{dmidfrac{n}{d^{'}}}mu(d) = f(n))
莫比乌斯函数还有两个很神奇的性质:
1.(sum_{d|n}mu (d)=[n==1])
2.(sum_{d|n}frac{mu (d)}{d}=frac {phi (d)}{d})
以下为线性筛莫比乌斯函数的代码
int cnt, prime[N], mu[N], vis[N];
void get_mu(int n) {
mu[1] = 1;
for(int i = 2; i <= n; i++) {
if(!vis[i]) pime[++cnt] = i, mu[i] = -1;
for(int j = 1; j <= cnt && i*prime[j] <= n; j++) {
vis[i*prime[j]] = 1;
if(i%prime[j] == 0) {
mu[i*prime[j]] = 0;
break;
}
mu[i*prime[j]] = -mu[i];
}
}
}