Sha256: d04ab399616bc012281e729a4a8ecfdc9efe53faaa3340ef9234dec717560699
Contents?: true
Size: 396 Bytes
Versions: 3
Compression:
Stored size: 396 Bytes
Contents
module AcLibraryRb def floor_sum(n, m, a, b) res = 0 if a >= m res += (n - 1) * n * (a / m) / 2 a %= m end if b >= m res += n * (b / m) b %= m end y_max = (a * n + b) / m return res if y_max == 0 x_max = (m * y_max - b + a - 1) / a res += (n - x_max) * y_max + floor_sum(y_max, a, m, a * x_max - m * y_max + b) res end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ac-library-rb-0.5.2 | lib_lock/ac-library-rb/floor_sum.rb |
ac-library-rb-0.5.1 | lib_lock/ac-library-rb/floor_sum.rb |
ac-library-rb-0.5.0 | lib_lock/ac-library-rb/floor_sum.rb |