mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-18 01:00:15 +00:00
04698538d8
Source: Snyk code quality Add scikit-fuzzy to requirements Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
36 lines
682 B
Python
36 lines
682 B
Python
"""
|
|
Project Euler Problem 1: https://projecteuler.net/problem=1
|
|
|
|
Multiples of 3 and 5
|
|
|
|
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.
|
|
"""
|
|
|
|
|
|
def solution(n: int = 1000) -> int:
|
|
"""
|
|
Returns the sum of all the multiples of 3 or 5 below n.
|
|
|
|
>>> solution(3)
|
|
0
|
|
>>> solution(4)
|
|
3
|
|
>>> solution(10)
|
|
23
|
|
>>> solution(600)
|
|
83700
|
|
"""
|
|
|
|
result = 0
|
|
for i in range(n):
|
|
if i % 3 == 0 or i % 5 == 0:
|
|
result += i
|
|
return result
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(f"{solution() = }")
|