Integer Range Residue Count
Count congruent integers in an inclusive closed range using Euclidean residues, including negative endpoints.
Description
Count congruent integers in an inclusive closed range using Euclidean residues, including negative endpoints.
A residue class selects integers with the same remainder modulo a positive modulus. Counting within a closed range avoids enumerating every candidate.
When to use this tool
Count congruent integers in an inclusive closed range using Euclidean residues, including negative endpoints.
- Prepare the supplied start, end, modulus, residue fields for this operation.
- Compare the complete example with the representation used by your own input before carrying the result into another step.
How to use the tool and how it works
- Enter start, end, modulus, residue. Use the exact text syntax, units and index conventions explained below.
- Run the tool. If input validation fails, correct the supplied fields before interpreting any result.
- Read result.count, result.first. Interpret false, null and empty lists using the distinctions below; they can be valid outputs.
Validate ordered integer bounds, positive modulus and canonical residue. Normalize negative remainders, calculate the first qualifying integer at or after start, then use integer division to count through end inclusively; return null first when none exist.1
| Input field | Meaning and representation | Accepted input |
|---|---|---|
| start | start. | Integer from -1e12 to 1e12 inclusive |
| end | end. | Integer from start to 1e12 inclusive |
| modulus | modulus. | Integer from 1 to 1e9 inclusive |
| residue | residue. | Integer from 0 to modulus - 1 inclusive |
| Output field | Interpretation |
|---|---|
| result | Object containing the named outputs below. |
| result.count | The count value under the stated formula or text convention. |
| result.first | The first value under the stated formula or text convention. |
{
"input": {
"start": -3,
"end": 5,
"modulus": 3,
"residue": 1
},
"output": {
"result": {
"count": 3,
"first": -2
}
}
} Limitations and assumptions
- Bounds and modulus have explicit finite limits. This counts integers, not continuous interval length, and uses a nonnegative remainder convention even for negative endpoints.
- Interval-array rows contain exactly two finite endpoints in start/end order, with at most 128 intervals per collection. Individual operations state when positive length, integer endpoints or explicit inclusion flags are required.
- Every declared top-level field is required and unexpected fields are rejected. Numeric inputs must be finite; ordinary text fields are bounded to 8,192 UTF-16 code units, with tighter operation-specific limits where stated.
- Ordinary string lists have at most 128 entries of at most 128 code units each; numeric lists and matrices have separate bounded size checks. Nonfinite results and excessively large serialized outputs are rejected.
- Indexes are zero-based and spans have an exclusive end unless explicitly stated otherwise. A valid false, null or empty-list result is distinct from malformed input.
Alternative or Complementary methods
Retain the endpoint convention with every result. Continuous length, integer point counts and open/closed membership differ; merge returned cells separately when a canonical minimal interval collection is required.
References
Similar or alternative tools
- Closed Integer Interval Overlap Count
Count shared integers in closed integer endpoint intervals, including one-point contact.
- Allen Interval Relation Classifier
Classify the 13 Allen relations between finite positive-length intervals, with A relative to B and exact endpoint equality.