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.
n: upper bound $$result = 3*\sum_{i=0}^{\left\lfloor \frac{n-1}{3} \right\rfloor} i + 5*\sum_{i=0}^{\left\lfloor \frac{n-1}{5} \right\rfloor} i - 15*\sum_{i=0}^{\left\lfloor \frac{n-1}{15} \right\rfloor} i$$
import math
def solve(bound):
def partial_sum(d):
item_num = math.floor((bound - 1) / d)
return int(item_num * (item_num + 1) / 2)
return 3 * partial_sum(3) + 5 * partial_sum(5) - 15 * partial_sum(15)
solve(10)
solve(1000)