Last active
September 11, 2020 21:14
-
-
Save betaprojects/c3d4aaa9b546cd1b53c8a13c649120db to your computer and use it in GitHub Desktop.
Project Euler & HackerRank problem 1 solution: Multiples of 3 and 5 - solved using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sumn(n, d): # Sum natural numbers ≤ n that are divisible by d | |
n //= d | |
return d*n*(n+1) // 2 | |
L = int(input('Enter an upper bound? ')) | |
a, b = 3, 5 | |
s = sumn(L-1, a) + sumn(L-1, b) - sumn(L-1, a*b) | |
print ("Sum of multiples of", a, "or", b, "below", L, "=", s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment