1
$\begingroup$

I'm trying to find how many numbers between 1 and 1000, which are not either prime or the sum of successive primes.

I've managed to create the list of all the primes between 1 and 1000:

primes = With[{list = Range[1000]}, Pick[list, PrimeQ[list]]]

And the sum:

sum[k_] := Sum[primes[[n]], {n, 1, k}]

which gives the summation of the primes from Prime[1] to Prime[k].

How can I adapt this summation to be the sum of successive primes?

i.e. Prime[1] + Prime[2] , Prime[2] + Prime[3] etc.?

And how can I use that to create a list of numbers which aren't prime or the sum of successive primes?

$\endgroup$
5
  • $\begingroup$ What do you mean by sum of successive primes? $\endgroup$
    – no-one
    Apr 13, 2018 at 21:37
  • $\begingroup$ Once the list of prime numbers is created, I want to create another list where I add the first and second primes, then the second and third primes, third and forth, and so on. i.e 2+3=5, 3+5=8, 5+7=12 etc. $\endgroup$ Apr 13, 2018 at 21:41
  • $\begingroup$ Have a look at Partition. $\endgroup$ Apr 13, 2018 at 21:52
  • $\begingroup$ Try this: (#1 + #2) & @@@ Partition[primes, 2, 1] $\endgroup$
    – no-one
    Apr 13, 2018 at 21:55
  • 1
    $\begingroup$ You might like BlockMap[Total, primes, 2, 1] $\endgroup$
    – chuy
    Apr 13, 2018 at 21:57

2 Answers 2

2
$\begingroup$

Here are the sums of successive primes, which are all the way upto $1088$

primeSums = Table[Prime[i + 1] + Prime[i], {i, 100}];

Here are primes upto 1069:

primes = Table[Prime[i], {i, 180}];

We consider the Complement of first 1000 numbers from these lists:

Complement[Range[1000], primes, primeSums]

which gives what you seek. For example, for the first 100 numbers, we get

Complement[Range[100], primes, primeSums]

{1, 4, 6, 9, 10, 14, 15, 16, 20, 21, 22, 25, 26, 27, 28, 32, 33, 34, 35, 38, 39, 40, 44, 45, 46, 48, 49, 50, 51, 54, 55, 56, 57, 58, 62, 63, 64, 65, 66, 69, 70, 72, 74, 75, 76, 77, 80, 81, 82, 85, 86, 87, 88, 91, 92, 93, 94, 95, 96, 98, 99}

$\endgroup$
0
$\begingroup$
With[{primes = Prime @ Range @ PrimePi @ 1000}, Length @ 
 Complement[Range @ 1000, primes, Total[Partition[primes, 2, 1], {2}]]]

739

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.