Skip to content

Instantly share code, notes, and snippets.

@BlueInkAlchemist
Created April 7, 2018 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BlueInkAlchemist/8e85a5831d6e3afff5d01521a269a139 to your computer and use it in GitHub Desktop.
Save BlueInkAlchemist/8e85a5831d6e3afff5d01521a269a139 to your computer and use it in GitHub Desktop.
Sum all multiples of 3 & 5 up to 1000, using Python
# 1. Get the upper bounds for the arithmetic series.
## Ensure that no limit reaches 1000.
LIMIT=999
upper_for_three = LIMIT // 3
upper_for_five = LIMIT // 5
upper_for_fifteen = LIMIT // 15
# 2. Calculate sums from within individual bounds.
sum_three = 3*upper_for_three*(1 + upper_for_three) / 2
sum_five = 5*upper_for_five*(1 + upper_for_five) / 2
sum_fifteen = 15*upper_for_fifteen*(1 + upper_for_fifteen) / 2
# 3. Calculate total of all sums.
total = sum_three + sum_five - sum_fifteen
# 4. Print the result in Terminal.
print(int(total))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment