题解 P3327 【[SDOI2015]约数个数和】

约数个数和

\[\begin{aligned} \sum_{i=1}^{n}\sum_{j=1}^{m}d(ij) & = \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}\:*\:{\left\lfloor\dfrac{n}{x}\right\rfloor}\:*\:{\left\lfloor\dfrac{m}{y}\right\rfloor}[gcd(x,y)=1] \\ & = \sum_{x=1}^{n}\sum_{y=1}^{m}{\left\lfloor\dfrac{n}{x}\right\rfloor}\:*\:{\left\lfloor\dfrac{m}{y}\right\rfloor}\:*\:\sum_{t|gcd(x,y)}\mu(t) \\ & = \sum_{t=1}^{min(n,m)}\mu(t)\times \sum_{x=1}^{\left\lfloor\dfrac{n}{t}\right\rfloor}\sum_{y=1}^{\left\lfloor\dfrac{m}{t}\right\rfloor}\left\lfloor\dfrac{n}{xt}\right\rfloor\:*\:\left\lfloor\dfrac{m}{xt}\right\rfloor \\ & = \sum_{t=1}^{min(n,m)}\mu(t)\times \sum_{x=1}^{\left\lfloor\dfrac{n}{t}\right\rfloor}\left\lfloor\dfrac{\left\lfloor\dfrac{n}{x}\right\rfloor}{t}\right\rfloor\times \sum_{x=1}^{\left\lfloor\dfrac{m}{t}\right\rfloor}\left\lfloor\dfrac{\left\lfloor\dfrac{m}{x}\right\rfloor}{t}\right\rfloor \end{aligned} \]

\[\text{莫比乌斯反演的“套路”} \text{设}f(x) = \sum_{i=1}^{x}{\left\lfloor\dfrac{x}{i}\right\rfloor} \]

\[ans=\sum_{t=1}^{min(n,m)}\mu(t)\times f(\left\lfloor\dfrac{n}{t}\right\rfloor)\times f(\left\lfloor\dfrac{m}{t}\right\rfloor) \]

\(\mu\)用前缀和

而f函数可以用数论分块\(O(\sqrt{N})\)

posted @ 2020-08-25 16:09  starseven  阅读(69)  评论(0编辑  收藏  举报