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.
x = 0
threeTotal = 0
fiveTotal = 0
threeMultiple = 0
fiveMultiple = 0
total = 0
while (threeTotal < 10):
threeMultiple += 3
threeTotal += threeMultiple
while (fiveTotal < 10):
fiveMultiple += 5
fiveTotal += fiveMultiple
fiveTotal + threeTotal
33
total = 0
threeTotal = 0
threeMultiple = 0
fiveTotal = 0
fiveMultiple = 0
for i in range(10):
print i
if i%3 == 0:
print "three", i
total += i
if i%5 == 0:
print "five", i
total += i
if i%3 == 0 and i%5 == 0:
print "both", i
total -= i
print total
0 three 0 five 0 both 0 1 2 3 three 3 4 5 five 5 6 three 6 7 8 9 three 9 23
total = 0
for i in range(10):
if i%3 == 0 or i%5 == 0:
print i
total += i
print total
0 3 5 6 9 23
sum([ i for i in range(1000) if i%3 == 0 or i%5 == 0 ])
233168