Pagination Page Count
A paginated API needs to tell clients how many pages exist and how many items sit on the final (possibly partial) page. Given the total item count and the page size, compute both without floating-point rounding bugs.
Problem
Given non-negative integer total and positive integer pageSize, return [pages, lastPageCount] where pages is the number of pages needed (ceil(total / pageSize)) and lastPageCount is the number of items on the last page. If total is 0, return [0, 0].
Input
Integers total (0 ≤ total ≤ 10^18) and pageSize (1 ≤ pageSize ≤ 10^9).
Output
A two-element array [pages, lastPageCount].
Constraints
- 0 ≤ total ≤ 10^18
- 1 ≤ pageSize ≤ 10^9
- Use integer arithmetic only — no floating point
Examples
Example 1
Input
total = 23, pageSize = 10
Output
[3, 3]
23 items over pages of 10 → 3 pages; the last page holds 23 − 20 = 3 items.
Example 2
Input
total = 20, pageSize = 10
Output
[2, 10]
20 divides evenly into 2 full pages; the last page holds a full 10.