the built-in One-Liner is not too bad
In[3]:= Remove[twoprimesum]
twoprimesum[n_Integer] := Length[IntegerPartitions[n, {2}, Table[Prime[o], {o, PrimePi[n]}], 1]] > 0 /; n > 2
In[7]:= twoprimesum[12345678] // Timing
Out[7]= {2.480416, True}
but of course, in this specific case one can do better
In[37]:= Remove[twoPrimeSumQ]
twoPrimeSumQ[n_Integer?Positive] := Which[n < 4, False, 3 < n < 7, True, True, Return[$Failed]] /; n < 7
twoPrimeSumQ[n_Integer?Positive] := Block[{s, bContinue = True},
s = NextPrime[n, -1];
While[bContinue && s > Floor[n/2],
If[PrimeQ[n - s],
bContinue = False, (* else *)
s = NextPrime[s, -1]
]
];
If[!bContinue, Print[n " = ", n - s, " + ", s]];
!bContinue
] /; n > 6
In[40]:= twoPrimeSumQ[12345678] // Timing
During evaluation of In[40]:= 12345678 = 31 + 12345647
Out[40]= {0., True}
In[41]:= twoprimesum[12345678] // Timing
Out[41]= {2.496016, True}
In[42]:= twoPrimeSumQ[12345677] // Timing
Out[42]= {15.288098, False}
In[43]:= TimeConstrained[twoprimesum[12345677], 300] // Timing
Out[43]= {296.807503, $Aborted}
and this new twoPrimeSumQ[] is rather stupid because it simply drops down the ladder of primes. Possibly one could do better by dropping down
and stepping up from NextPrime[Floor[n/2]] and so on and so on and so on .... in any case NextPrime[] is a very good work horse, because of
In[44]:= NextPrime[100000000000000000000000000000000000000000000000000000000000000] // Timing
Out[44]= {0.015600, 100000000000000000000000000000000000000000000000000000000000447}