-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path23.py
53 lines (47 loc) · 1.03 KB
/
23.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
48
49
50
51
52
53
import math
from itertools import combinations
def prod(l):
prod = 1
for e in l:
prod *= e
return prod
def pf(n):
l = []
while n % 2 == 0:
n //= 2
l.append(2)
for i in range(3, math.ceil(math.sqrt(n)) + 1, 2):
while n % i == 0:
n //= i
l.append(i)
if n > 1:
l.append(n)
return l
def pd(n):
lpf = pf(n)
pd = set(lpf)
for i in range(2, len(lpf)):
for e in list(combinations(lpf, i)):
pd.add(prod(e))
pd.add(1)
try:
pd.remove(n)
except:
pass
return pd
abundant_numbers = set() ## using a set here because 'in' is O(1)
for i in range(12, 28124):
if sum(pd(i)) > i:
abundant_numbers.add(i)
tot = 0
for i in range(1, 28124):
if i in abundant_numbers and i/2 in abundant_numbers:
continue
for e in abundant_numbers:
if e > i:
tot += i
break
other = i - e
if other in abundant_numbers:
break
print(tot)