首页 > 代码库 > [补档计划] 类欧几里得算法

[补档计划] 类欧几里得算法

$$\begin{aligned} f(a, b, c, n) & = \sum_{i = 0}^n \lfloor \frac{ai + b}{c} \rfloor \\ & = \sum_{i = 0}^n \sum_{j = 0}^{m-1} [j < \lfloor \frac{ai + b}{c} \rfloor] \\ & = \sum_{i = 0}^n \sum_{j = 0}^{m-1} [j + 1 \le \lfloor \frac{ai + b}{c} \rfloor] \\ & = \sum_{i = 0}^n \sum_{j = 0}^{m-1} [j + 1 \le \frac{ai+b}{c}] \\ & = \sum_{i = 0}^n \sum_{j = 0}^{m-1} [cj + c - b \le ai] \\ & = \sum_{i = 0}^n \sum_{j = 0}^{m-1} [cj + c - b -1 < ai] \\ & = \sum_{i = 0}^n \sum_{j = 0}^{m-1} [\frac{cj + c - b - 1}{a} < i] \\ & = \sum_{i = 0}^n \sum_{j = 0}^{m-1} [\lfloor \frac{cj + c - b - 1}{a} \rfloor < i] \\ & = \sum_{j = 0}^{m-1}\sum_{i = 0}^n [\lfloor \frac{cj + c - b - 1}{a} \rfloor < i] \\ & = \sum_{j = 0}^{m-1} (n+1 - \sum_{i = 0}^n [\lfloor \frac{cj + c - b - 1}{a} \rfloor \ge i]) \\ & = \sum_{j = 0}^{m-1} (n+1 -\lfloor \frac{cj + c - b - 1}{a} \rfloor - 1) \\ & = \sum_{j = 0}^{m-1} (n - \lfloor \frac{cj + c - b - 1}{a} \rfloor) \\ & = m \times n - \sum_{j = 0}^{m-1} \lfloor \frac{cj + (c - b - 1)}{a} \rfloor \\ & = m \times n - f(c, c-b-1, a, m-1) \end{aligned} $$

[补档计划] 类欧几里得算法