Problem 21
This commit is contained in:
parent
39030caf40
commit
30003d04d7
28
0021.py
Normal file
28
0021.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# amicable pairs
|
||||||
|
|
||||||
|
from functools import reduce
|
||||||
|
import util
|
||||||
|
|
||||||
|
target = 31626
|
||||||
|
|
||||||
|
def sum_proper_divisors (nbr):
|
||||||
|
proper_divisors = util.divisors(nbr)[0:-1]
|
||||||
|
|
||||||
|
return reduce(lambda x, y: x + y, proper_divisors)
|
||||||
|
|
||||||
|
r = 10000
|
||||||
|
|
||||||
|
amicable_numbers = []
|
||||||
|
|
||||||
|
for i in range(1, r + 1):
|
||||||
|
s = sum_proper_divisors(i)
|
||||||
|
|
||||||
|
if (s != i and sum_proper_divisors(s) == i):
|
||||||
|
amicable_numbers.append(i)
|
||||||
|
|
||||||
|
|
||||||
|
sum_amicables = reduce(lambda x, y: x + y, amicable_numbers)
|
||||||
|
|
||||||
|
print(sum_amicables)
|
||||||
|
print(sum_amicables == target)
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user