-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem23.py
39 lines (35 loc) · 851 Bytes
/
problem23.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
import time
start = time.time()
def sumOfDivisors(n):
total = 1
p = 2
while p*p <= n and n > 1:
if n%p == 0:
j = p*p
n = n/p
while n % p == 0:
j = j*p
n = n/p
total *= (j-1)
total /= (p-1)
if p == 2:
p = 3
else:
p += 2
if n > 1:
total *= (n+1)
return total
def sumOfProperDivisors(n):
return int(sumOfDivisors(n) - n)
abundant = []
for i in range(1, 28123):
if sumOfProperDivisors(i) > i:
abundant.append(i)
numbers = [x for x in range(28123)]
for i in range(len(abundant)):
for j in range(i, len(abundant)):
if abundant[i] + abundant[j] < 28123:
numbers[abundant[i] + abundant[j]] = 0
else:
break
print(sum(numbers))