标签:
Orz jcpwfloi大爷!
题目要求$\sum_{i = 1} ^ {n} \sum_{j = 1} ^ {m} d(i \times j)$
我们首先可以推出一个非常简单的结论,就是$$\sum_{i = 1} ^ {n} d(i) = \sum_{i = 1} ^ {n} \biggl \lfloor \frac{n} {i} \biggr \rfloor $$
在二维中,不放令$g = gcd(i, j)$,则$d(i \times j) = d(g) \times d(\frac{i} {g}) \times (\frac {j} {g})$,故(不妨设m ≤ n):
$$\begin {align} ans &= \sum_{i = 1} ^ {n} \sum_{j = 1} ^ {m} d(i \times j) \\&= \sum_{i = 1} ^ {n} \sum_{j = 1} ^ {m} d(g) \times d(\frac{i} {g}) \times (\frac {j} {g})\\&= \sum_{g = 1} ^ {n} d(g) \sum_{i = 1} ^ {\lfloor \frac{n} {g} \rfloor} \sum_{j = 1} ^ {\lfloor \frac{m} {g} \rfloor} d(i) \times d(j) \times [gcd(i, j) == 1]\\&= \sum_{g = 1} ^ {n} d(g) \sum_{i = 1} ^ {\lfloor \frac{n} {g} \rfloor} \sum_{j = 1} ^ {\lfloor \frac{m} {g} \rfloor} d(i) \times d(j) \times \sum_{d = 1} ^ {gcd(i, j)} \mu (d)\\&= \sum_{g = 1} ^ {n} d(g) \sum_{d = 1} ^ {\lfloor \frac{n} {g} \rfloor} \mu (d) (\sum_{i = 1} ^ {\lfloor \frac{n} {gd} \rfloor} d(i) \times \sum_{j = 1} ^ {\lfloor \frac{m} {gd} \rfloor} d(j))\\\end {align}$$
这样子预处理出来d(i)的前缀和已经可以在$O(\sqrt{n} \times \sqrt{n}) = O(n)$的时间内进行一次查询了
不妨再令$f(i) = \sum_{j = 1} ^ {i} d(j)$,则:
$$\begin {align} ans &= \sum_{g = 1} ^ {n} d(g) \sum_{d = 1} ^ {\lfloor \frac{n} {g} \rfloor} \mu (d) f(\lfloor \frac{n} {gd} \rfloor) f(\lfloor \frac{m} {gd} \rfloor) \\ \end {align}$$
标签:
原文地址:http://www.cnblogs.com/rausen/p/4436902.html