pub fn floor_sum(n: i64, m: i64, a: i64, b: i64) -> i64
Expand description
Returns
$$\sum_{i = 0}^{n - 1} \left\lfloor \frac{a \times i + b}{m} \right\rfloor.$$
It returns the answer in $\bmod 2^{\mathrm{64}}$, if overflowed.
§Constraints
- $0 \leq n \lt 2^{32}$
- $1 \leq m \lt 2^{32}$
§Panics
Panics if the above constraints are not satisfied and overflow or division by zero occurred.
§Complexity
- $O(\log{(m+a)})$
§Example
use ac_library::math;
assert_eq!(math::floor_sum(6, 5, 4, 3), 13);