Adopted new convention from template
This commit is contained in:
parent
b0b380bdd8
commit
20893290f4
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Created on 05 Jan 2019
|
||||
|
||||
@ -9,6 +9,8 @@ Solution for problem 23 of Project Euler
|
||||
https://projecteuler.net/problem=23
|
||||
"""
|
||||
|
||||
from itertools import product
|
||||
|
||||
from utils import timeit
|
||||
|
||||
|
||||
@ -34,25 +36,27 @@ def compute():
|
||||
Find the sum of all the positive integers which cannot be written as the
|
||||
sum of two abundant numbers.
|
||||
"""
|
||||
LIMIT = 28124
|
||||
divisorsum = [0] * LIMIT
|
||||
for i in range(1, LIMIT):
|
||||
for j in range(i * 2, LIMIT, i):
|
||||
divisorsum[j] += i
|
||||
abundantnums = [i for (i, x) in enumerate(divisorsum) if x > i]
|
||||
|
||||
expressible = [False] * LIMIT
|
||||
for i in abundantnums:
|
||||
for j in abundantnums:
|
||||
if i + j < LIMIT:
|
||||
limit = 28124
|
||||
divisor_sum = [0] * limit
|
||||
for i in range(1, limit):
|
||||
for j in range(i * 2, limit, i):
|
||||
divisor_sum[j] += i
|
||||
|
||||
abundant_nums = [i for (i, x) in enumerate(divisor_sum) if x > i]
|
||||
|
||||
expressible = [False] * limit
|
||||
for i in abundant_nums:
|
||||
for j in abundant_nums:
|
||||
if i + j < limit:
|
||||
expressible[i + j] = True
|
||||
else:
|
||||
break
|
||||
|
||||
ans = sum(i for (i, x) in enumerate(expressible) if not x)
|
||||
|
||||
return ans
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
print(f"Result for Problem 23: {compute()}")
|
||||
print(f"Result for Problem 23 is {compute()}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user