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. I have the following code but the answer do
Just as an improvement you might want to avoid the loop altogether :
multiples of 3 below 1000 form an AP : 3k where k in [1, 333]
multiples of 5 below 1000 form an AP : 5k where k in [1, 199]
If we avoid multiples of both 3 and 5 : 15k where k in [1, 66]
So the answer is : 333*(3+999)/2 + 199(5+995)/2 - 66*(15+990)/2 = 233168
Why you might want to do this is left to you to figure out.