Home Project Euler Teaching Projects Gallery

Problem 1 statement:

P1: 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.


Algorthim:

Pretty simple problem. This was when I started learning Python; hence, the code may seem very.... awkward and not well optimized. Essential we sum the all multiples of three and five separately. Then subtract integers that were counted twice: multiples of 15.

sum3 represents sum of all multiples of three
sum5 represents sum of all multiples of five
sum15 represents sum of multiples of 15

Code:

Result:

Answer: 233168
Runtime: 1.16 ms