Project Euler

Multiples of 3 and 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.

Plan

To figure this problem out, we must first find the sum of the multiples of 3 (under 1000). Then we must find the sum of the multiples of 5 (under 1000). Then we add the two sums up.

Pseudocode

  1. set number variable to 0
  2. set initial sum to 0
  3. set initial counter to 0
  4. create loop that goes to 1000
  5. add numbers to sum that are divisible by 3 or 5
  6. print out sum

Solution



Home Page