题解
这个故事告诉们数论函数不要往分式上跑,你推不出来
好久没推式子了这么明显的转化我都忘了= =
首先\(A(n) = \frac{1}{n} \sum_{i = 1}^{n} \frac{i * n}{gcd(i,n)}\)
然后显然可以把n消掉
\(A(n) = \sum_{i = 1}^{n} \frac{i}{gcd(i,n)}\)
改为枚举约数
\(A(n) = \sum_{d = 1}^{n} \frac{1}{d}\sum_{i = 1}^{n} i [gcd(i,n) == d]\)
\(A(n) = \sum_{d | n} \sum_{i = 1}^{\frac{n}{d}} i [gcd(i,\frac{n}{d}) == 1]\)
有个欧拉函数的性质是,小于这个数的且与这个数互质的数的和是
\(\frac{n \phi(n) + [n = 1]}{2}\) 挺好理解的,因为一个与n互质的数p,n - p也和n互质
\(\frac{n \phi(n) + [n = 1]}{2} = \sum_{i = 1}^{n} i [gcd(i,n) == 1]\)
\(A(n) = \frac{1}{2} (\sum_{d | n} \frac{n}{d} \phi(\frac{n}{d}) + 1)\)
\(F(n) = \sum_{i = 1}^{n} A(i)\)
\(F(n) = \frac{1}{2} (\sum_{i = 1}^{n} \sum_{d | i} \frac{i}{d} \phi(\frac{i}{d}) + n)\)
\(F(n) = \frac{1}{2} (\sum_{i = 1}^{n} \sum_{d | i} d \phi(d) + n)\)
\(F(n) = \frac{1}{2} (\sum_{i = 1}^{n} \sum_{d = 1}^{\frac{n}{i}} d \phi(d) + n)\)
我们发现这个东西可以构造卷积啊
\(\sum_{d = 1}^{n} d \phi(d)\)
卷上一个\(Id(x) = x^{2}\)
那么我们就有
\(\sum_{i = 1}^{n} i^2 = \sum_{i = 1}^{n} \sum_{d | i}d \phi(d) \frac{i}{d}\)
\(\sum_{i = 1}^{n} i^2 = \sum_{k = 1}^{n} k \sum_{d = 1}^{\frac{n}{k}}d \phi(d)\)
那么就有
\(S(n) = \frac{n(n +1)(2n + 1)}{6} - \sum_{i = 2}^{n} i S(\lfloor \frac{n}{i} \rfloor)\)
然后用数论分块求\(F(n)\)即可
题解
#include
#include
#include
#include
#include
#include
#include