Created
November 10, 2019 00:49
-
-
Save voith/aa474cb35abe8716283210111a9dd166 to your computer and use it in GitHub Desktop.
sum of all the positive integers which cannot be written as the sum of two abundant numbers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt | |
def sum_of_divisors(number): | |
_sum = 1 | |
nsqrt = int(sqrt(number)) | |
for i in range(2, nsqrt + 1): | |
if number % i == 0: | |
_sum += i | |
if (number / i != nsqrt): | |
_sum += number // i | |
return _sum | |
def is_abundant(number): | |
_sum_div = sum_of_divisors(number) | |
if _sum_div > number: | |
return True | |
else: | |
return False | |
upper_limit = 28123 + 100 | |
tracker = [False] * (upper_limit + 1) | |
tracker[12] = True | |
abundant_numbers = [12] | |
_sum = sum(range(1, 13)) | |
for num in range(13, upper_limit + 1): | |
if is_abundant(num): | |
tracker[num] = True | |
abundant_numbers.append(num) | |
for i in abundant_numbers: | |
if tracker[num - i]: | |
break | |
else: | |
_sum += num | |
print(_sum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment