Sums of Primes

Which even numbers up to 20000 are not sums of two primes less than 10000? This question can be answered in Euler Math Toolbox in the following way.

>p=primes(10000);
>v=unique(flatten(p+p'));
>x=4:2:20000;
>i=nonzeros(indexof(v,x)==0);
>x[i]
[19504,  19750,  19804,  19822,  19834,  19840,  19866,  19876,  19884,
19886,  19888,  19892,  19894,  19900,  19906,  19910,  19912,  19918,
19920,  19924,  19926,  19928,  19930,  19932,  19936,  19938,  19942,
19944,  19948,  19950,  19952,  19954,  19956,  19958,  19960,  19962,
19964,  19966,  19968,  19970,  19972,  19974,  19976,  19978,  19980,
19982,  19984,  19986,  19988,  19990,  19992,  19994,  19996,  19998,
20000]

The p+p‘ part computes all sums of primes up to 10000. We flatten this vector, and generate a version with unique elements. Then we test if all even numbers up to 20000 are in that list. Some are not.

Actually, this is certainly not the most efficient way, but it works.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.