Files
euler-project/problems/001_problem.py
2020-04-14 21:01:53 -04:00

37 lines
597 B
Python

# Problem 1:
#
# 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.
import decorators
def check_divisibility(num, dict_multiples: dict) -> bool:
dummy = 1
for m in dict_multiples:
dummy *= num%m
if dummy == 0:
return True
else:
return False
@decorators.function_timer
def main():
multiples = {3,5}
sumval = 0
for n in range(1000):
r = check_divisibility(n,multiples)
if r:
sumval += n
print(sumval)
main()