Tuesday, November 11, 2008

Problem 1

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.

------------------------------------------------------------------------

I figured programming something for this would be a bit of overkill. So here is the algebraic solution:

(Sum of Multiples of 3 or 5) = Sum(Multiples of 3) + Sum(Multiples of 5) - Sum(Multiples of 3*5 = 15)

The only thing we'll need to solve this is the formula for the sum of the first N natural numbers, which is N*(N+1)/2 (Gaussian method)

Sum(Multiples of 3) = 3 + 6 + ... + 999 = 3*(1 + 2 + ... + 333) = 3*(333)*(334)/2 = 166833

Sum(Multiples of 5) = 5 + 10 + ... + 995 = 5*(1 + 2 + ... + 199) = 5*(199)*(200)/2 = 99500

Sum(Multiples of 15) = 15 + 30 + ... + 990 = 15*(1 + + 2 + ... + 66) = 15*(66)*(67)/2 = 33165

/******* Solution *******/

Sum(Multiples of 3) + Sum(Multiples of 5) - Sum(Multiples of 3*5 = 15) = 166833 +99500 - 33165 = 233168