# ProjectEuler_做题记录

#### problem 441 The inverse summation of coprime couples

$\begin{array}{c} S(n) & = & \sum_{i = 1} ^ n \sum_{p = 1} ^ i \sum_{q = p + 1} ^ i \frac {1}{pq}[p + q \geq i][gcd(p, q) = 1] \\ & = & \sum_{i = 1} ^ n \sum_{p = 1} ^ i \sum_{q = p + 1} ^ i \frac {1}{pq}[p + q \geq i] \sum_{d|gcd(p, q)} \mu(d) \\ & = & \sum_{i = 1} ^ n \sum_{d = 1} ^ n \mu(d) \sum_{p = 1} ^ {\lfloor i/d \rfloor} \sum_{q = 1} ^ {\lfloor i/d \rfloor} \frac {1}{pqd ^ 2}[pd + qd \geq i]\\ & = & \sum_{i = 1} ^ n \sum_{d = 1} ^ n \frac {\mu(d)}{d ^ 2} \sum_{p = 1} ^ {\lfloor i/d \rfloor} \sum_{q = 1} ^ {\lfloor i/d \rfloor} \frac {1}{pq}[p + q \geq \lfloor i/d \rfloor] \\ & - & \frac {1}{pq}[p + q = \lfloor i/d \rfloor][i \ mod \ d = 0] \\ \end{array}$

$\begin{array}{c} F(n) & = & \sum_{i = 1} ^ n \frac {1}{i} \\ G(n) & = & \sum_{i = 1} ^ n \sum_{j = i + 1} ^ n \frac {1}{ij} [i + j = n] \\ T(n) & = & \sum_{i = 1} ^ n \sum_{j = i + 1} ^ n \frac {1}{ij} [i + j \geq n] \\ \end{array}$

$S(n) = \sum_{d = 1} ^ n \frac {\mu(d)}{d ^ 2} \sum_{i = d} ^ n(T(\lfloor i/d \rfloor) - G(\lfloor i/d \rfloor)[i \ mod \ d \neq 0])$

#### problem 530 GCD of Divisors

$\begin{array}{c} ans & = & \sum_{i = 1} ^ n \sum_{d \mid i} gcd(d, \frac {i}{d}) \\ & = & \sum_{g = 1} ^ n g \sum_{i = 1} ^ {n} \sum_{d \mid i} [gcd(d, \frac {i}{d}) = g]（先枚举gcd的套路）\\ & = & \sum_{g = 1} ^ n g \sum_{i = 1} ^ {\lfloor n/g^2 \rfloor} \sum_{d \mid i} [gcd(d, \frac {i}{d}) = 1]（设i = \frac {i}{g ^ 2}, d = \frac {d}{g}）\\ & = & \sum_{g = 1} ^ n g \sum_{i = 1} ^ {\lfloor n/g^2 \rfloor} \sum_{d \mid i} \sum_{t \mid gcd(d, \frac {i}{d})} \mu(t) \\ & = & \sum_{g = 1} ^ n g \sum_{t = 1} ^ n \mu(t) \sum_{i = 1} ^ {\lfloor n/(gt) ^ 2 \rfloor} \sum_{d \mid i} 1 （设i = \frac {i}{t ^ 2}, d = \frac {d}{t}，也是套路）\\ & = & \sum_{g = 1} ^ n g \sum_{t = 1} ^ n \mu(t) \sum_{i = 1} ^ {\lfloor n/(gt) ^ 2 \rfloor} \sigma_0(i)（\sigma_0(i)表示i的因子个数）\\ &!&（下一步是个新套路，构造\phi的卷积形式\phi = \mu * 1） \\ & = & \sum_{k = 1} ^ {\sqrt n} \sum_{g \mid k} g\mu(\frac {k}{g}) \sum_{i = 1} ^ {\lfloor n/k ^ 2 \rfloor} \sigma_0(i)（k = gt，注意k的取值只需要到\sqrt n）\\ & = & \sum_{k = 1} ^ {\sqrt n} \phi(k) \sum_{i = 1} ^ {\lfloor n/k ^ 2 \rfloor} \sigma_0(i)\\ &!& （最后套用\sum_{i = 1} ^ {m} \sigma_0(i) = \sum_{i = 1} ^ m \lfloor \frac {m}{i} \rfloor）\\ & = & \sum_{k = 1} ^ {\sqrt n} \phi(k) \sum_{i = 1} ^ {\lfloor n/k ^ 2 \rfloor} \lfloor \frac {\lfloor n/k ^ 2 \rfloor}{i} \rfloor \\ \end{array}$

posted @ 2018-08-20 14:40 PinkExSu0v0 阅读(...) 评论(...) 编辑 收藏