51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
import math
|
|
from functools import reduce
|
|
|
|
def factors(x):
|
|
result = [1]
|
|
i = 2
|
|
while i*i <= x: #Other way of writing i<=sqrt(x)
|
|
if x % i == 0:
|
|
result.append(i)
|
|
if x//i != i:
|
|
result.append(x//i)
|
|
i += 1
|
|
return result
|
|
|
|
def is_abundant(n):
|
|
return sum(factors(n)) > n
|
|
|
|
abundants= [i for i in range(28123) if is_abundant(i)]
|
|
|
|
range28 = [range(28123+1)]
|
|
abundantsums = []
|
|
result = []
|
|
for i in range(len(abundants)):
|
|
for j in range(len(abundants)-i):
|
|
if abundants[i]+abundants[i-j]<=28123 and abundants[i]+abundants[i-j] in range28:
|
|
abundantsums.append(abundants[i]+abundants[i-j])
|
|
range28.pop(range28.index(abundants[i]+abundants[i-j]))
|
|
result.append(abundants[i]+abundants[i-j])
|
|
print(len(abundantsums)) #24 266 061
|
|
print("calculated abundantsums")
|
|
|
|
|
|
|
|
#result = sum([i for i in range(28123+1) if not i in abundantsums])
|
|
|
|
# result = 0
|
|
# for i in range(28123+1):
|
|
# print(i)
|
|
# if not i in abundantsums:
|
|
# result+=i
|
|
|
|
# range28 = [range(28123+1)]
|
|
# result = []
|
|
# for i in abundantsums:
|
|
# if i in range28:
|
|
# range28.pop(range28.index(i))
|
|
# result.append(i)
|
|
|
|
print(result)
|
|
|