-
Notifications
You must be signed in to change notification settings - Fork 0
/
euler023.py
47 lines (41 loc) · 959 Bytes
/
euler023.py
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
import math
def sumfactors(n):
s = 1
for i in range(2, int(math.floor(math.sqrt(n))) + 1):
if n % i == 0:
s = s + i
if i != (n // i):
s = s + (n // i)
#print(str(i) + ',' + str(n // i))
#else:
#print(str(i) + '[x2]')
#print(str(n) + ', ' + str(s))
return s
limit = 28123
ab = []
for i in range(2, limit + 1):
if i < sumfactors(i):
ab.append(i)
#print(i)
N = list(range(limit + 1))
for i in range(len(ab)):
for j in range(i, len(ab)):
if ab[i] + ab[j] <= limit:
N[ab[i] + ab[j]] = 0
#print(ab[i] + ab[j])
else:
break
print(sum(N))
"""
total = 0
for n in range(limit + 1):
for i in range(len(ab)):
if ab[i] < n:
if n - ab[i] in ab:
break
else:
total += n
print(n)
break
print(total)
"""