Ceiling count for fixed-size batches (source code)

= Ceiling count for fixed-size batches
{title2=$b=\lceil N/k\rceil$}

Suppose $N$ is a nonnegative <integer> count of items and each batch holds at most $k$ items, where $k$ is a positive <integer>. The smallest sufficient number of batches is
$$
b=\left\lceil\frac Nk\right\rceil.
$$
Indeed, $bk\geq N$ exactly when the <integer> $b$ is at least $N/k$. If $N=0$, no batches are needed. If $N$ is a multiple of $k$, no partly filled batch is needed.

For $102$ items with capacity $20$ per batch, $b=\lceil5.1\rceil=6$. Five batches can be full and the sixth holds two items, leaving $6\cdot20-102=18$ unused places. This is a different question from the five complete groups counted by $\lfloor102/20\rfloor$.

\Image[/integer-interval-and-batch-counts.png]
{title=Endpoint-aware integer counts and six twenty-place batches needed for 102 items}

Writing the <Euclidean division> $N=kq+r$, $0\leq r<k$, gives the equivalent rule $b=q$ when $r=0$, and $b=q+1$ when $r>0$. This explains the <ceiling function>'s jump: one extra item beyond a complete multiple demands a whole additional batch. For exact <integer arithmetic>, the identity $b=\lfloor(N+k-1)/k\rfloor$ avoids a fractional intermediate value; an implementation still needs an <integer> representation large enough to hold $N+k-1$.