OFFSET
2,4
COMMENTS
A067076 is a subsequence of this sequence: when 2m+3 is prime a(m+3) = m. Moreover, it is the subsequence of records (maximal increasing subsequence): let m=a(n), with p=n-m and q=p+2m both odd primes > 3; now 3+2(m+(p-3)/2)=q and hence a(3+m+(p-3)/2) >= m+(p-3)/2 > m = a(n) but 3+m+(p-3)/2 < n. - Jason Kimberley, Aug 30 2012 and Oct 10 2012
Goldbach's conjecture says a(n) >= 0 for all n. - Robert Israel, Apr 15 2015
a(n) is the Goldbach partition of 2n which results in the maximum spread divided by 2. - Robert G. Wilson v, Jun 18 2018
LINKS
T. D. Noe, Table of n, a(n) for n = 2..10000
OEIS (Plot 2), A067076 vs A098090 (n-m=3). - Jason Kimberley, Oct 01 2012
FORMULA
a(n) = n - A020481(n).
EXAMPLE
49-30=19 and 49+30=79 are primes, so a(49)=30.
MAPLE
a:= proc(n)
local k;
for k from n - 1 to 0 by -2 do
if isprime(n+k) and isprime(n-k) then return(k) fi
od:
-1
end proc:
0, seq(a(n), n=3..1000); # Robert Israel, Apr 16 2015
MATHEMATICA
a[2] = a[3] = 0; a[n_] := (For[m = n - 2, m >= 0, m--, If[PrimeQ[n - m] && PrimeQ[n + m], Break[]]]; m); Table[a[n], {n, 2, 100}] (* Jean-François Alcover, Sep 04 2013 *)
lm[n_]:=Module[{m=n-2}, While[!AllTrue[n+{m, -m}, PrimeQ], m--]; m]; Join[{0, 0}, Array[ lm, 70, 4]] (* The program uses the AllTrue function from Mathematica version 10 *) (* Harvey P. Dale, Dec 03 2014 *)
f[n_] := Block[{q = 2}, While[q <= n && !PrimeQ[2n -q], q = NextPrime@ q]; n - q]; Array[f, 72, 2] (* Robert G. Wilson v, Jun 18 2018 *)
PROG
(PARI) a(n) = {if (n==2 || n==3, return (0)); my(m = 1, lastm = -1, do = 1); while (do, if (isprime(n-m) && isprime(n+m), lastm = m); m++; if (m == n - 1, do = 0); ); return (lastm); } \\ Michel Marcus, Jun 09 2013
(PARI) a(n)=if(n<4, 0, forprime(p=3, n-1, if(isprime(2*n-p), return(n-p))); -1) \\ Ralf Stephan, Dec 29 2013
(Haskell)
a047949 n = if null qs then -1 else head qs where
qs = [m | m <- [n, n-1 .. 0], a010051' (n+m) == 1, a010051' (n-m) == 1]
-- Reinhard Zumkeller, Nov 02 2015
CROSSREFS
KEYWORD
easy,nice,nonn
AUTHOR
EXTENSIONS
Corrected by Harvey P. Dale, Dec 21 2000
STATUS
approved