202108050932 Project Euler Problem 1 solved by C

Problem 1 of Project Euler

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.

Ans. 233168


(step-by-step approach, slow but sure logic)

I wish to find all the multiples of 3 (excluding multiples of 5) below 1000:

Then I wish to find all the multiples of 5 (excluding multiples of 3) below 1000:

Lastly I wish to find all the multiples of 15=3\times 5 below 1000:

In sum,

\begin{aligned} & \quad \textrm{The sum of all multiples of 3 or 5 below 1000} \\ & = 133\small,668 + 66\small,335 + 33\small,165 \\ & = 233\small,168 \end{aligned}

Ans. 233168 \quad\checkmark

(to be continued)


Going off at a tangent, the sum of all numbers from 1 to 1000 is 500500. See:

(proof)

\begin{aligned} & \quad 1+2+3+\cdots +1000 \\ & = \sum_{k=1}^{1000}k \\ & = \frac{(1000)(1000+1)}{2} \\ & = 500500 \\ \end{aligned}


(continue)

Solution. (fast and furious attempt)