-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem21.py
More file actions
30 lines (27 loc) · 829 Bytes
/
problem21.py
File metadata and controls
30 lines (27 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def sumProperDivisors(n):
divisors = [1]
maxDivisor = n
number = 2
while (number < maxDivisor):
if n % number == 0:
divisors.append(number)
divisors.append(int(n/number))
maxDivisor = n/number
number = number + 1
divisors.sort()
return(sum(divisors))
amicableNumbers = []
for i in range(1,10000):
# d(a) = b
sumDivisors = sumProperDivisors(i)
# if a != b
if not sumDivisors == i:
# d(b) = ?
sumOtherDivisors = sumProperDivisors(sumDivisors)
# if d(b) = a
if sumOtherDivisors == i:
if i not in amicableNumbers:
amicableNumbers.append(i)
if sumOtherDivisors not in amicableNumbers:
amicableNumbers.append(sumOtherDivisors)
print(amicableNumbers)