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.
This isn’t a problem that can be done very quickly by hand, so let’s just let the code speak for itself:
if counter%3==0 or counter%5==0:
The time tools let me time how long it takes. When running this from the command prompt I get a time of .0019998550415 seconds, and it gets the right answer (which I’ll leave out in case you don’t want the spoiler).
Does anyone have a better way of getting code published on here?