# 浅谈莫比乌斯反演的常见套路

## 莫比乌斯反演的套路

emmm，因为我做过的题太少了，所以可能非常不全。

### $\sum_{i = 1}^n \sum_{j = 1}^m gcd(i, j) = k$

\begin{aligned}
&\sum_{i = 1}^n \sum_{j = 1}^m gcd(i, j) = k \
&\sum_{i = 1}^{\frac{n}{k}} \sum_{j = 1}^{\frac{m}{k}} [gcd(i, j)]\
&\sum_{i = 1}^{\frac{n}{k}} \sum_{j = 1}^{\frac{m}{k}} \sum_{d \ | gcd(i, j)} \mu(d)\
&\sum_{i = 1}^{\frac{n}{k}} \sum_{j = 1}^{\frac{m}{k}} \sum_{d \ | i} \sum_{d \ | j}\mu(d)\
&\sum_{d = 1}^n \mu(d) \sum_{i = 1}^{\frac{n}{k}} \sum_{d \ | i} \sum_{j = 1}^{\frac{m}{k}}\sum_{d \ | j} 1\
&\sum_{d = 1}^n \mu(d) \frac{n}{kd} \frac{m}{kd}\
\end{aligned}

#### 题目

BZOJ1101: [POI2007]Zap

### $\sum_{i = 1}^n \sum_{j = 1}^m gcd(i, j)$

\begin{aligned}
&\sum_{d = 1}^n \sum_{i = 1}^n \sum_{j = 1}^m gcd(i, j) = d \
&\text{后面的一坨直接按照第一种套路推，最终会得到}\
&\sum_{d = 1}^n \sum_{k=1}^n \mu(k) \frac{n}{kd} \frac{m}{kd}\
&\text{设$T = kd$}\
&\sum_{T = 1}^n \frac{n}{T} \frac{m}{T} \sum_{d \ | T} d \mu(\frac{T}{d})
\end{aligned}

#### 题目

BZOJ4407: 于神之怒加强版

BZOJ4804: 欧拉心算

### $\prod_{i = 1}^n \prod_{j = 1}^m gcd(i, j)$

\begin{aligned}
&\prod_{d = 1}^n d^{{\sum_{i = 1}^n \sum_{j=1}^m} gcd(i, j) = d}\
&\text{然后按照上面的套路推，可以得到下面的式子}\
&\prod_{d = 1}^n d^{\sum_{k=1}^{\frac{n}{d}} \mu(k) \frac{n}{kd}\frac{m}{kd}}\
&\text{设$T= kd$，枚举$T$}\
&\prod_{T = 1}^n (\prod_{d \ | T} d^{\mu(\frac{T}{d})})^{\frac{n}{T} \frac{m}{T}}\
\end{aligned}

$g(T) = \prod_{d \ | T} d^{\mu(\frac{T}{d})}$

$T$为质数的幂时, 设$T = p^q$，那么$g(T) = p$，除此之外$g(T) = 1$

#### 拓展

$\sum_{i = 1}^n \sum_{j = 1}^m f(gcd(i, j))$

## 参考资料

posted @ 2018-12-10 19:58  自为风月马前卒  阅读(625)  评论(4编辑  收藏

……