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)
| 28 | |
| 29 | |
| 30 | def 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 | |
| 52 | if __name__ == "__main__": |
no test coverage detected