How many positive odd integers between 0 and 999 inclusive can be written as sum of 3 odd composite positive integers?
clearvars,clc
had=zeros(1,999);
oddComp=setdiff(3:2:999,primes(999));
idx=combinator(length(oddComp),3,'c');
list=oddComp(idx);
for i=1:length(list)
s=sum(list(i,:));
if s<1000
had(s)=1;
end
end
sum(had)
idx=combinator(length(oddComp),2,'p');
list=oddComp(idx);
for i=1:length(list)
s=list(i,1)*2+list(i,2);
if s<1000
if had(s)==0
fprintf('%d ',s);
end
had(s)=1;
end
end
disp(' ')
sum(had)
for i=1:length(oddComp)
s=3*oddComp(i);
if s<1000
if had(s)==0
fprintf('%d ',s);
end
had(s)=1;
end
end
disp(' ')
sum(had)
finds
ans =
476
39 33 43 53
ans =
480
27
ans =
481
If the three numbers must be unique, there are 476 such numbers; if duplicates are allowed, there are 481 such. The numbers 33, 39, 43 and 53 require that two of the numbers be the same and 27 requires all three the same (of course that's 9).
|
Posted by Charlie
on 2024-11-08 08:54:32 |