How this calculation works
This calculator sums the floors of an entire rational arithmetic progression using exact integer reductions. The term count can be enormous because the algorithm does not enumerate every index. Negative coefficients and offsets are normalized using mathematical floor division, preserving the direction of rounding for negative values. The reduction trace shows the smaller reciprocal counting problems used to obtain the final integer total.
S(n,m,a,b)=Σ_(i=0)^(n−1) floor((a i+b)/m). Normalize a,b by floor division, then apply Euclidean lattice-counting reductions.A worked example
With n=5,a=3,b=1,m=5, the indexed terms are floor(1/5), floor(4/5), floor(7/5), floor(10/5) and floor(13/5). Their values 0,0,1,2 and 2 sum to five. The last index is four. If n were incorrectly treated as an inclusive final index, an extra term floor(16/5)=3 would change the answer to eight.
Good to know
The term count is a nonnegative integer and m is a positive integer. Absolute values of a,b and all nonnegative counts/denominators are at most 10^30. Indices begin at zero. The operation uses floor, not truncation toward zero or rounding to nearest. A zero term count returns zero. No floating-point approximation, arbitrary real coefficient or infinite series is supported.
Reference: AtCoder Library — exact floor sum specification (opens in a new tab) ↗
Term count and inclusive bounds are different inputs
The sum on this page always uses n terms, starting at index zero. To sum from a positive index L through U inclusive, use n=U−L+1 and replace b by aL+b. That change of index preserves every original numerator while fitting the page’s declared zero-based form. Leaving b unchanged would instead evaluate a different part of the progression.
For example, to sum floor((3i+1)/5) for i=2,3,4, enter n=3,a=3,b=7,m=5. The terms are 1,2 and 2, totaling five. This is the same final three terms of the default example. Such small direct expansions help verify an indexing convention before much larger inputs make manual enumeration impractical.
The Floor and ceiling of a number calculator rounds individual values. This page sums a whole indexed progression using exact Euclidean reductions.
Negative numerators need genuine floor division
The floor of −1/5 is −1, not zero. Languages that divide signed integers by truncating toward zero therefore need an explicit correction when the remainder is negative. This calculator applies mathematical floor division when extracting the integer quotients of a and b. After normalization, their remainders lie between zero and m−1.
If a=q m+r and b=s m+t, each term contributes q i+s plus floor((r i+t)/m). The removed part sums to q n(n−1)/2+s n exactly. This identity handles signed inputs without forcing the main geometric reduction to work with negative slope or offset. For n=3,a=−1,b=0,m=2, the terms 0,−1,−1 give −2.
Counting lattice strips creates a smaller problem
Once the slope and offset are normalized, the sum can be read as counting integer levels below a line across a finite strip. Exchanging the counting direction swaps the roles of slope and denominator. The resulting recurrence follows the same decreasing-remainder structure as Euclid’s algorithm, so a large term count need not imply a long calculation.
The trace records accumulated contributions and the parameters of each transformed problem. These intermediate parameters are algorithmic counting regions, not a list of the original summands. A direct check on small cases and exact recurrence identities provide stronger validation than converting a huge sum into a decimal estimate. If a requested application requires ceiling instead, transform the expression algebraically rather than interpreting this floor result as a ceiling.
A few questions, answered
Can n be zero?
Yes. An empty finite sum is zero. The denominator must still be positive and all other inputs must satisfy their bounds.
Why do negative examples differ from integer truncation?
Floor moves toward negative infinity. Truncation toward zero is a different operation whenever the quotient is negative and nonintegral.