I wanted to summarize solutions to this question based on `IntegerPartitions`

, `FrobeniusSolve`

, and a new hybrid method.

The first method `f1[n]`

based on `IntegerPartitions`

finds pairs of primes summing to `n`

. @Mr.Wizard found this method to be slow for long lists in the third argument. Hence, he proposed function `f3[n]`

to enumerate all pairs then filter.

```
f1[n_] := IntegerPartitions[n, {2}, Prime@Range@PrimePi@n]
f3[n_] := Cases[IntegerPartitions[n, {2}], {__?PrimeQ}]
```

For reasonably large `n=1787834`

, function `f3[n]`

is much faster.

```
With[{n = 1787834}, {AbsoluteTiming[Length@f1[n]], AbsoluteTiming[Length@f3[n]]}]
(* {{10.5924, 6643}, {0.809354, 6643}} *)
```

The first two methods, `f4[n]`

and `f5[n]`

, based on `FrobeniusSolve`

are from @Mr.Wizard and @AntonAntonov, respectively. The third method `f6[n]`

adapts `f5[n]`

by using Pick instead of Select.

```
f4[n_] := Cases[FrobeniusSolve[{1, 1}, n], {__?PrimeQ}]
f5[n_] := Select[FrobeniusSolve[{1, 1}, n], And @@ Map[PrimeQ, #] &]
f6[n_] := Pick[#, And @@@ PrimeQ[#]] &[FrobeniusSolve[{1, 1}, n]]
```

`Pick`

is faster than `Select`

, but the fastest formulation is `f4[n]`

with `Cases`

. The number of solutions is twice as large because both solutions `{p,q}`

and `{q,p}`

are returned. Since half of 1787834 is prime, there is also a solution `{p,p}`

which is not duplicated.

```
With[{n = 1787834}, {
AbsoluteTiming[Length@f4[n]],
AbsoluteTiming[Length@f5[n]],
AbsoluteTiming[Length@f6[n]]}]
(* {{2.55104, 13285}, {5.35851, 13285}, {3.78575, 13285}} *)
```

The hybrid solution recognises that `FrobeniusSolve[{1,1},n]`

simply returns pairs of integers `{k,n-k}`

for `k=0,1,...,n`

, and tests each pair for primality. Function `f7[n]`

begins with a list of primes `p`

about half as long as for `f1[n]`

, then tests for prime `n-p`

.

```
f7[n_] := Block[{p = Prime[Range[PrimePi[Quotient[n, 2]]]]},
Transpose[{#, n - #} &[Pick[p, PrimeQ[n - p]]]]
]
```

Reversed solutions are not returned by `f7[n]`

, so the count is again 6643. The timing is about 10 times faster than the best solution so far, `f3[n]`

.

```
AbsoluteTiming[Length@f7[1787834]]
(* {0.062481, 6643} *)
```

2Interesting variation. I didn't expect this to be competitive with

`IntegerPartitions`

, but it seems that on larger numbers it is. Also I believe that your filter can be improved; try:`AbsoluteTiming[ Cases[FrobeniusSolve[{1, 1}, 120022], {__?PrimeQ}]; ]`

– Mr.Wizard – 2016-12-04T11:52:06.513Please see the addendum to my answer. – Mr.Wizard – 2016-12-04T12:07:04.370

@Mr.Wizard Thanks for pointing out the speed-up with

`Cases`

/`__?PrimeQ]`

! I was not aware that it can be that significant. – Anton Antonov – 2016-12-04T22:27:38.527