Ad

Even faster, since it doesn't rely on an iterator. Especially big numbers yield noticeable differences in execution time.

Code
Diff
  • def euler(num):
        sum_range = lambda x: x*(x+1)//2
        return 3*sum_range((num-1)//3) + 5*sum_range((num-1)//5) - 15*sum_range((num-1)//15)
    • def euler(num):
    • return sum(range(3,num,3)) + sum(range(5,num,5)) - sum(range(15,num,15))
    • sum_range = lambda x: x*(x+1)//2
    • return 3*sum_range((num-1)//3) + 5*sum_range((num-1)//5) - 15*sum_range((num-1)//15)