-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_023.py
More file actions
36 lines (28 loc) · 761 Bytes
/
_023.py
File metadata and controls
36 lines (28 loc) · 761 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
32
33
34
35
36
import math
def divisors(n):
ds = []
for d in range(1, int(math.sqrt(n)) + 1):
if n % d == 0:
ds.append(d)
x = n // d
if x != d and x != n: ds.append(x)
return ds
N = 28123
def calc_abundant_numbers(N):
abundant_numbers = []
for i in range(1, N + 1):
if sum(divisors(i)) > i:
abundant_numbers.append(i)
return abundant_numbers
abundant_numbers = calc_abundant_numbers(N)
an = len(abundant_numbers)
answer = N * (N + 1) // 2
memo = set()
for i in range(an):
for j in range(i, an):
a = abundant_numbers[i]
b = abundant_numbers[j]
if a + b <= N and a + b not in memo:
memo.add(a + b)
answer -= (a + b)
print(answer)