Problem 1 "Multiples of 3 and 5"
Of the natural numbers less than 10, there are four that are multiples of 3 or 5, and the sum of these is 23. In the same way, find the sum of the numbers that are multiples of 3 or 5 less than 1000.
Python
seq = range(1000)
result = 0
for i in seq:
if i % 3 == 0 or i % 5 == 0:
result += i
print result
print result == 233168
result
233168
True
Recommended Posts