Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Recipe

Apply the Division Algorithm

Use when: you're given integers a and b, with b positive, and need the quotient q and remainder r satisfying a = bq + r

Goal: the one pair of integers q and r with 0 \le r < b

Taught in Divisibility, parity, and remainders

  1. 1

    Divide a by b to get a decimal, then round that decimal down toward negative infinity, never toward zero, to get the integer q.

    Example

    For a=-17, b=5: -17 \div 5 = -3.4. Round toward negative infinity, not toward zero, so q=-4, one step past -3.

    • a is positive — rounding down and rounding toward zero land on the same integer, so ordinary division already gives q.
    • a is negative and doesn't divide evenly — rounding down lands one integer further from zero than rounding toward zero would.

    Why: only rounding down guarantees the remainder computed next lands in the required range 0 \le r < b.

  2. 2

    Multiply b by the q from Step 1, then subtract that product from a to get r.

    Example

    Continuing with a=-17, b=5, q=-4: bq = 5(-4) = -20, so r = -17 - (-20) = 3.

    Why: rearranging a=bq+r for r gives exactly this subtraction, the only value of r that keeps the equation true for this q.

  3. 3

    Confirm the remainder from Step 2 is not negative and strictly less than b; if either check fails, q was rounded the wrong way.

    Example

    Here r=3, and 0 \le 3 < 5, so q=-4, r=3 passes. Rounding toward zero instead would give q=-3, and r = -17 - 5(-3) = -2, which fails the check since it's negative.

    Why: this range is what makes q and r unique, exactly what the Division Algorithm guarantees.

Common mistakes

  • Rounding a \div b toward zero instead of down when a is negative, producing a negative remainder.
  • Skipping the check in Step 3 and accepting a remainder outside 0 \le r < b.
  • Subtracting in the wrong order, computing bq - a instead of a - bq.
  • Applying this recipe with a negative b, where the Division Algorithm as stated here doesn't apply.