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

Function solution

project_euler/problem_021/sol1.py:30–49  ·  view source on GitHub ↗

Returns the sum of all the amicable numbers under n. >>> solution(10000) 31626 >>> solution(5000) 8442 >>> solution(1000) 504 >>> solution(100) 0 >>> solution(50) 0

(n: int = 10000)

Source from the content-addressed store, hash-verified

28
29
30def solution(n: int = 10000) -> int:
31 """Returns the sum of all the amicable numbers under n.
32
33 >>> solution(10000)
34 31626
35 >>> solution(5000)
36 8442
37 >>> solution(1000)
38 504
39 >>> solution(100)
40 0
41 >>> solution(50)
42 0
43 """
44 total = sum(
45 i
46 for i in range(1, n)
47 if sum_of_divisors(sum_of_divisors(i)) == i and sum_of_divisors(i) != i
48 )
49 return total
50
51
52if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

sum_of_divisorsFunction · 0.70

Tested by

no test coverage detected