What is the largest even positive integer that cannot be expressed as the sum of two composite odd numbers?
Brian Smith's solution is elegant.
My computer program also found 38
-------------
from itertools import combinations_with_replacement
oddcomps = [2*i+1 for i in range(1,2000) if not isprime(2*i+1)]
winningEvens = []
for c in combinations_with_replacement(oddcomps,2):
x = sum(c)
if x not in winningEvens:
winningEvens.append(x)
mylist = sorted(winningEvens)[::-1]
start = mylist[0]
cannotbe = []
for i in range(start, 0, -2):
if i not in mylist:
cannotbe.append(i)
print(cannotbe[0])
|
Posted by Larry
on 2024-06-18 11:43:54 |