⬅︎ Back to Faster way to sum an integer series in Python
There are some problems in your post. Summing the integers between 1 and 5 inclusive is 15, but that's not `sum(range(5))`--it's `sum(range(1, 6))`. There's a similar issue with summing 1 through 15 (and the value of 109 doesn't work at all). The formula you want is `n*(n+1)//2`.
Comment
There are some problems in your post. Summing the integers between 1 and 5 inclusive is 15, but that's not `sum(range(5))`--it's `sum(range(1, 6))`. There's a similar issue with summing 1 through 15 (and the value of 109 doesn't work at all).
The formula you want is `n*(n+1)//2`.