How many positive odd integers between 0 and 999 inclusive can be written as sum of 3 odd composite positive integers?
There are 332 odd composites < 1000.
Check all combinations of this set taken 3 at a time; the sums will all be odd. Will use "combinations_with_replacement" to account for duplicates.
There are 481 positive odd integers between 0 and 999 inclusive which can be written as sum of 3 odd composite positive integers.
This includes all but 5 of the 7 smallest odd composites; in addition, it includes 154 odd primes.
---------------
from itertools import combinations_with_replacement
oddcomposites = [n for n in range(3,1000,2) if not isprime(n)]
ans = []
for comb in combinations_with_replacement(oddcomposites, 3):
sum3 = sum(comb)
if sum3 > 999:
continue
if sum3 not in ans:
ans.append(sum3)
print(len(ans))
|
Posted by Larry
on 2024-11-08 10:55:41 |