Counting Integers in an Interval: Inclusive vs Exclusive

Determining the count of integers in an interval

  • The key task: decide whether endpoints are inclusive or exclusive, then count how many integers lie in that range.
  • Strategy: translate the interval into the corresponding set of integers and use a simple subtraction (+1 if inclusive) to get the count.
  • A common pitfall is forgetting the off-by-one when using a naive last − first calculation.

Inclusive endpoints

  • If the interval includes both endpoints a and b (a ≤ b) — i.e., [a, b] with integer endpoints — the number of integers is
    N=ba+1.N = b - a + 1.
  • Example from transcript (inclusive): from 11 to 99 inclusive
    • First = 11, Last = 99
    • Count: N=9911+1=89.N = 99 - 11 + 1 = 89.
  • Important note: this formula assumes a and b are integers and a ≤ b. If a > b, the count is 0 by convention.

Exclusive endpoints

  • If the interval excludes both endpoints (a, b) with integers a < b, the number of integers is
    N=ba1.N = b - a - 1.
  • Explanation: the first integer inside the interval is a + 1, the last is b - 1, so
    N=(b1)(a+1)+1=ba1.N = (b - 1) - (a + 1) + 1 = b - a - 1.
  • Example from transcript (exclusive): from 105 to 330 exclusive
    • First inside = 106, Last inside = 329
    • Count: N=329106+1=224N = 329 - 106 + 1 = 224 or equivalently N=3301051=224.N = 330 - 105 - 1 = 224.
  • If only one endpoint is exclusive or if the interval is half-open, adjust accordingly using the same principle.

General case with non-integer endpoints

  • When endpoints are real numbers (not necessarily integers), count the integers x that satisfy a ≤ x ≤ b is
    N=ba+1,N = \lfloor b \rfloor - \lceil a \rceil + 1,
    provided the result is nonnegative.
  • If the interval is a < x < b (strict inequalities) with real a, b, the count is
    N=max(0,ba1).N = \max\left(0, \lceil b \rceil - \lfloor a \rfloor - 1\right).
  • These formulas reduce to the integer-endpoint formulas when a and b are integers.

Worked examples from the transcript

  • Example 1 (inclusive): 11 to 99 inclusive
    • N = 9911+1=89.99 - 11 + 1 = 89.
  • Example 2 (exclusive): 105 to 330 exclusive
    • First = 106, Last = 329
    • Count: N=329106+1=224.N = 329 - 106 + 1 = 224. or equivalently N=3301051=224.N = 330 - 105 - 1 = 224.
  • Note: The transcript emphasized confirming the calculation with a calculator, i.e., verify the arithmetic.

Quick method recap

  • Inclusive endpoints [a, b]: N=ba+1.N = b - a + 1.
  • Exclusive endpoints (a, b): N=ba1.N = b - a - 1.
  • Non-integer endpoints: inclusive: N=ba+1.N = \lfloor b \rfloor - \lceil a \rceil + 1.
  • Non-integer endpoints: exclusive: N=max(0,ba1).N = \max\left(0, \lceil b \rceil - \lfloor a \rfloor - 1\right).
  • Always verify the end conditions (whether inclusive or exclusive) before applying the formula to avoid off-by-one errors.