-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_021.py
More file actions
49 lines (41 loc) · 1.31 KB
/
Copy pathproblem_021.py
File metadata and controls
49 lines (41 loc) · 1.31 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Date: 2020.07.22
# Answer:31626
import math
# copied from problem 12
def properDivisors(val):
#returns list of divisors not including itself
# [values, num of divisors, sum of divisors]
divisors = {1}
for i in range(2,math.ceil(math.sqrt(val))):
if val % i == 0:
divisors.update([i,val/i])
#print(divisors)
#print(val,len(divisors),int(sum(divisors)))
return [val,len(divisors),int(sum(divisors))]
def check_amicable(val,divList):
tmp = divList[val][2]
#print(val,numDivisorsList[tmp][2])
if(tmp<len(divList) and not(val==tmp)):
return val == divList[tmp][2]
return False
def createDivisorsList(upperBound):
properDivisorsList = [[0,0,-1],[1,1,1]]
for i in range(2,upperBound+1):
properDivisorsList.append(properDivisors(i))
return properDivisorsList
def createAmicableNumsList(inputList):
amicableNums = []
for i in inputList:
if(check_amicable(i[0],inputList)):
amicableNums.append(i[0])
#print(i[0])
return amicableNums
# print(numDivisorsList)
# print(numDivisorsList[220])
# print(numDivisorsList[228])
# print(numDivisorsList[1000][1])
# print(check_amicable(220))
# print(numDivisors(220))
a = createDivisorsList(10000)
#createAmicableNumsList(a)
print(sum(createAmicableNumsList(a)))