标题
增加 1 行删除 1 行
18.1(莫比乌斯反演)18.1 & 8.2(莫比乌斯反演)
正文
增加 70 行删除 1 行
30 行未改动31323334353637383940118 行未改动全部展开15916016116230 行未改动#### 倍数形式若$$F(n) = \sum_{n|d}f(d)$$则$$f(n) = \sum_{n|d}F(d)\mu(\frac{n}{d})$$## P2398首先,枚举 $gcd(i,j)$,那么原式为$$\begin{aligned}118 行未改动全部展开cin >> n >> m, solve(n, m);return 0;}```30 行未改动31323334353637383940414243118 行未改动全部展开16216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023130 行未改动#### 倍数形式若$$F(n) = \sum_{n|d}f(d)$$则$$f(n) = \sum_{n|d}F(d)\mu(\frac{d}{n})$$### $\mu$ 和 $\varphi$ 的关系$$\sum_{d|k} d\cdot \mu(\frac{k}{d}) = \varphi(k)$$## P2398首先,枚举 $gcd(i,j)$,那么原式为$$\begin{aligned}118 行未改动全部展开cin >> n >> m, solve(n, m);return 0;}```## P1447由题,令 $N = min(n, m)$答案为$$\begin{aligned}\sum_{i=1}^n\sum_{j=1}^m 2 \times gcd(i,j) + 1 &=nm + 2 \times \sum_{i=1}^n\sum_{j=1}^m gcd(i,j)\\&= nm + 2 \times \sum_{d = 1}^{N}f(d) \times d\\&= nm + 2 \times \sum_{d=1}^{N}d\sum_{k = 1}^{\lfloor\frac{N}{d}\rfloor}F(dk) \cdot \mu(k)\\&= nm + 2 \times \sum_{T = 1}^{N}F(T)\sum_{d|T} \cdot \mu(\frac{T}{d}) \cdot d\\&= nm + 2 \times \sum_{T = 1}^{N}F(T)\varphi(T)\end{aligned}$$因为 $F(d)$ 为 $gcd$ 为 $d$ 的倍数的数对个数,所以 $F(d) = \lfloor \frac{n}{d} \rfloor \lfloor \frac{m}{d} \rfloor$。所以原式等于$$nm + 2 \times \sum_{T = 1}^{N}\lfloor \frac{n}{T} \rfloor \lfloor \frac{m}{T} \rfloor\varphi(T)$$数论分块求出即可。## P3327### 前置公式$$d(ij) = \sum_{x|i}\sum_{y|j}[gcd(x,y)=1]$$所以原式为$$\sum_{i=1}^n\sum_{j=1}^m\sum_{x|i}\sum_{y|j}[gcd(x,y)=1] = \sum_{x=1}^n\sum_{y=1}^m[gcd(x,y)=1]\lfloor\frac{n}{x}\rfloor\lfloor\frac{m}{y}\rfloor$$设$$f(k) = \sum_{x=1}^n\sum_{y=1}^m[gcd(x,y)=k]\lfloor\frac{n}{x}\rfloor\lfloor\frac{m}{y}\rfloor$$而$$\begin{aligned}F(k) &= \sum_{x=1}^n\sum_{y=1}^m[k|gcd(x,y)]\lfloor\frac{n}{x}\rfloor\lfloor\frac{m}{y}\rfloor\\&= \sum_{x=1}^{\lfloor\frac{n}{k}\rfloor}\sum_{y=1}^{\lfloor\frac{m}{k}\rfloor}\lfloor\frac{n}{xk}\rfloor\lfloor\frac{m}{yk}\rfloor\end{aligned}$$令$$g(k) = \sum_{i=1}^k\lfloor\frac{k}{i}\rfloor$$则$$F(k) = g(\lfloor\frac{n}{k}\rfloor)g(\lfloor\frac{m}{k}\rfloor)$$那么$$\begin{aligned}f(k) &= \sum_{k|d}\mu(\frac{d}{k})F(d)\\&= \sum_{k|d}\mu(\frac{d}{k})g(\lfloor\frac{n}{d}\rfloor)g(\lfloor\frac{m}{d}\rfloor)\end{aligned}$$答案 $f(1)$ 即为$$\sum_{d}^{min(n, m)}\mu(d)g(\lfloor\frac{n}{d}\rfloor)g(\lfloor\frac{m}{d}\rfloor)$$预处理 $g$ 后数论分块求出。