Trait nekolib::math::linear_floor_sum::LinearFloorSum
source · pub trait LinearFloorSum {
// Required method
fn linear_floor_sum(self, m: Self, a: Self, b: Self) -> Self;
}
Expand description
$ \sum_{i=0}^{n-1} \left\lfloor\frac{ai+b}{m}\right\rfloor. $
Requirements
- $n \ge 0$
- $m \gt 0$
Idea
あとで書く。
See also
- https://rsk0315.hatenablog.com/entry/2020/12/13/231307
- https://atcoder.jp/contests/practice2/editorial/579
Examples
use nekolib::math::LinearFloorSum;
assert_eq!(4_u128.linear_floor_sum(10, 6, 3), 3);
assert_eq!(6_u128.linear_floor_sum(5, 4, 3), 13);
assert_eq!(1_u128.linear_floor_sum(1, 0, 0), 0);
assert_eq!(31415_u128.linear_floor_sum(92653, 58979, 32384), 314095480);
assert_eq!(
1000000000_u128.linear_floor_sum(1000000000, 999999999, 999999999),
499999999500000000
);
assert_eq!(14_i128.linear_floor_sum(23, -7, -39), -58);