MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_001/sol6.py:13–35  ·  view source on GitHub ↗

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

(n: int = 1000)

Source from the content-addressed store, hash-verified

11
12
13def solution(n: int = 1000) -> int:
14 """
15 Returns the sum of all the multiples of 3 or 5 below n.
16
17 >>> solution(3)
18 0
19 >>> solution(4)
20 3
21 >>> solution(10)
22 23
23 >>> solution(600)
24 83700
25 """
26
27 a = 3
28 result = 0
29 while a < n:
30 if a % 3 == 0 or a % 5 == 0:
31 result += a
32 elif a % 15 == 0:
33 result -= a
34 a += 1
35 return result
36
37
38if __name__ == "__main__":

Callers 1

sol6.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected