Although I am sure that there is an O (1) solution for this problem, clarifying this would not be practical, given that you were asked to provide an answer of 1000.
I agree with Matthew that the sum should be a local variable, but otherwise your code also looks good.
solution without code (just for fun):
Using the fact that sum(1+2+3+...+n) = n(n+1)/2 , we can get that the sum of multiples of x below 1000 is floor(1000/x)*(floor(1000/x)+1)/2*x .
The answer we need is the sum of multiples of 3 below 1000, plus the sum of multiples of 5, minus the sum of multiples of 15 (which would otherwise be double).
There are 999/3 = 333 times 3 below 1000, 999/5 = 199 times 5 below 1000, and 999/15 = 66 times 15 below 1000
So, the sum of all multiples of 3 is below 1000 = 333 * 334/2 * 3 = 166833, the sum of multiples of 5 is below 1000 = 199 * 200/2 * 5 = 99500, and the sum of multiples of 15 is below 1000 = 66 * 67/2 * 15 = 33165
Response execution 166833 + 99500 - 33165 = 233168
Luke hutteman
source share