LOJ6241 性能优化

更好的阅读体验

题意

\[T = \sum_{1\le i\le n}\sum_{1\le j\le\lfloor \frac{n}{i} \rfloor}\sum_{1\le k\le j}[\gcd(j,k)=1] \]

多组数据

\(n\le 10^{10^6}\)

题解

\[T = \sum_{1\le i\le n}\sum_{1\le j\le\lfloor \frac{n}{i} \rfloor}\varphi(j) \]

\[\text{S}(n) = \sum_{1\le i\le n}\varphi(i) \]

则有

\[\begin{align*} T &= \sum_{1\le i\le n}\text{S}(\lfloor \frac{n}{i} \rfloor) \\ &= \text{S}(n) + \sum_{2\le i\le n}\text{S}(\lfloor \frac{n}{i} \rfloor) \\ \end{align*}\]

根据杜教筛,由 \(\varphi*\text{I}=\text{Id}\),有

\[\text{I}(1)\times \text{S}(n)=\sum_{1\le i\le n}\text{Id}(i)-\sum_{2\le i\le n}\text{S}(\lfloor\frac{n}{i}\rfloor)\times \text{I}(i) \]

\[\text{S}(n)=\frac{n(n+1)}{2}-\sum_{2\le i\le n}\text{S}(\lfloor\frac{n}{i}\rfloor) \]

带回原式得

\[\begin{align*} T=&\frac{n(n+1)}{2}-\sum_{2\le i\le n}\text{S}(\lfloor\frac{n}{i}\rfloor) + \sum_{2\le i\le n}\text{S}(\lfloor \frac{n}{i} \rfloor)\\ =&\frac{n(n+1)}{2} \end{align*} \]

posted @ 2021-01-15 23:01  gzezFISHER  阅读(84)  评论(0编辑  收藏  举报