60 lines
1.2 KiB
Python
60 lines
1.2 KiB
Python
import os
|
|
import math
|
|
import numpy as np
|
|
|
|
# Find the sum of all positive integers which cannot be written as the sum
|
|
# of two abundant numbers.
|
|
|
|
# A number is abundant if its properdivisors sum to
|
|
# more than the original number, e.g. 12 is abundant, since 12 can be divided
|
|
# by 1, 2, 3, 4, 6 = 16
|
|
|
|
# It can be proven that all numbers above 28123 can be written as the sum
|
|
# of 2 abundant numbers
|
|
|
|
def getDivisors(n):
|
|
divs = [True] * math.ceil(n/2)
|
|
|
|
for x in range(1, len(divs)):
|
|
if divs[x] and n % (x + 1) != 0:
|
|
y = x
|
|
while y < len(divs):
|
|
divs[y] = False
|
|
y = y + x + 1
|
|
|
|
res = []
|
|
for x in range(len(divs)):
|
|
if divs[x]:
|
|
res.append(x + 1)
|
|
return res
|
|
|
|
def isAbundant(n):
|
|
return sum(getDivisors(n)) > n
|
|
|
|
|
|
def main():
|
|
print("Hello, this is Patrick")
|
|
|
|
m = 28123
|
|
|
|
a = list(filter(isAbundant, range(1, m+1)))
|
|
|
|
# We are assuming that the abundants are sorted
|
|
sums = set([])
|
|
for i in range(len(a)):
|
|
for j in range(i, len(a)):
|
|
s = a[i] + a[j]
|
|
if s > m:
|
|
break
|
|
else:
|
|
#print(s)
|
|
sums.add(s)
|
|
|
|
nonsums = set(range(1, m+1))
|
|
nonsums.difference_update(sums)
|
|
# print(nonsums)
|
|
print(sum(nonsums))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |