Lesson goal: Consecutive integer sums of 100

Previous: The erased blackboard average | Home | Next: The spiraling bug walk

In the 1973 MAA Annual High School Mathematics Examination (Part 3, Problem #26), students were challenged with:

"The number of sets of two or more consecutive positive integers whose sum is 100 is: (A) 1 (B) 2 (C) 3 (D) 4 (E) 5."

Let a sequence of $k$ consecutive positive integers start at $a \ge 1$: $$a, \quad a + 1, \quad a + 2, \quad \dots, \quad a + k - 1$$ The sum of these $k$ numbers is: $$\text{Sum} = k \cdot a + \frac{(k - 1)k}{2} = \frac{k(2a + k - 1)}{2} = 100$$ Multiplying both sides by 2 gives: $$k(2a + k - 1) = 200$$ This is a product of two positive integers whose product is $200$. Notice two key mathematical properties:
  1. Since $a \ge 1$, we have $2a + k - 1 \ge k + 1 > k$.
  2. The difference between the two factors is $(2a + k - 1) - k = 2a - 1$, which is always odd!
Therefore, one factor must be odd and the other must be even. Factoring $200 = 2^3 \times 5^2$: The odd factor can be $1$, $5$, or $25$:
  • Odd factor = 1: $k = 1 \implies 2a = 200 \implies a = 100$. But the problem specifies two or more integers ($k \ge 2$), so this is excluded!
  • Odd factor = 5: Setting $k = 5$ gives $2a + 4 = 40 \implies 2a = 36 \implies a = 18$.
    The 5 numbers are: $18 + 19 + 20 + 21 + 22 = 100$.
  • Odd factor = 25: Setting $2a + k - 1 = 25$ and $k = 8$ gives $2a + 7 = 25 \implies 2a = 18 \implies a = 9$.
    The 8 numbers are: $9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 = 100$.
Thus, there are exactly 2 sets!

In this lesson, we write nested loops and divisor algorithms in Lua to search for consecutive sequences that sum to 100, and generalize to any target number!

Now you try. Replace ???? with target and run the code to see the two sequences. Then try changing target = 45 or target = 64!

Type your code here:


See your results here: