forked from nayuki/Project-Euler-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp023.py
More file actions
31 lines (25 loc) · 691 Bytes
/
p023.py
File metadata and controls
31 lines (25 loc) · 691 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
31
#
# Solution to Project Euler problem 23
# Copyright (c) Project Nayuki. All rights reserved.
#
# https://www.nayuki.io/page/project-euler-solutions
# https://github.com/nayuki/Project-Euler-solutions
#
def compute():
LIMIT = 28124
divisorsum = [0] * LIMIT
for i in range(1, LIMIT):
for j in range(i * 2, LIMIT, i):
divisorsum[j] += i
abundantnums = [i for (i, x) in enumerate(divisorsum) if x > i]
expressible = [False] * LIMIT
for i in abundantnums:
for j in abundantnums:
if i + j < LIMIT:
expressible[i + j] = True
else:
break
ans = sum(i for (i, x) in enumerate(expressible) if not x)
return str(ans)
if __name__ == "__main__":
print(compute())