From charlesreid1

Revision as of 20:51, 13 June 2017 by Admin (talk | contribs) (Created page with "==Question== 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 multip...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Question

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.

Approach

Two-part problem: enumerating multiples of 3 or 5, and summing them up.

Task 1: generate all multiples of b, up to a given maximum N.

  • Given a maximum N, biggest number t hat can be a multiple of b is N/b.
  • Generate numbers from 1 to N/b.
  • Multiply them by b to generate numbers up to N that are multiples.
  • Use a set to keep all the numbers.

Task 2: sum them up.

  • Iterate over your set using a generator.