-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem21.py
More file actions
29 lines (25 loc) · 717 Bytes
/
Copy pathproblem21.py
File metadata and controls
29 lines (25 loc) · 717 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
import math
def listDiv(n):
div = [1]
cap = math.floor(math.sqrt(n))
for i in range(2,int(cap)):
if(n % i == 0):
div.append(i)
div.append(n/i)
return div
def sumList(lst):
tot = 0
for i in lst:
tot += i
return tot
amicNum = []
for i in range(1, 10000):
sumDiv = sumList(listDiv(i))
#print("sum of divisors of " + str(i) + " is " + str(sumDiv))
revSumDiv = sumList(listDiv(sumDiv))
#print("sum of divisors of " + str(sumDiv) + " is " + str(revSumDiv))
if(revSumDiv == i and i != sumDiv):
print("found amicable numbers!: " + str(i) + " " + str(sumDiv))
amicNum.append(i)
print(amicNum)
print(sumList(amicNum))