Back to Problems

Problem 1: Multiples of 3 or 5

If we list all the natural numbers below $10$ that are multiples of $3$ or $5$, we get $3, 5, 6$ and $9$. The sum of these multiples is $23$.

Find the sum of all the multiples of $3$ or $5$ below $1000$.

Solution Approach

There are more than one ways to approach this problem but this was the one that came to my mind first:

Consider the following fact:

For an arithmetic series with first term $a$, common difference $d$, and number of terms $n$, the sum of the series is given by:

$$S_n = \frac{n}{2} \left( 2a + (n - 1)d \right)$$

Let $a$ = sum of multiples of $3$ below $1000$

$$a = \frac{333}{2} \left( 2 \cdot 3 + (333 - 1) \cdot 3 \right)$$

Let $b$ = sum of multiples of $5$ below $1000$

$$b = \frac{199}{2} \left( 2 \cdot 5 + (199 - 1) \cdot 5 \right)$$

Let $c$ = sum of multiples of $5$ below $1000$

$$c = \frac{66}{2} \left( 2 \cdot 15 + (66 - 1) \cdot 15 \right)$$

In terms of python:

def arithmetic_sequence_sum(n, a, d):
    return n / 2 * (2 * a + (n - 1) * d)

a = arithmetic_sequence_sum(333, 3, 3)
b = arithmetic_sequence_sum(199, 5, 5)
c = arithmetic_sequence_sum(66, 15, 15)

print(a+b-c)

Running the above code leads to an answer of $233168$