login
A047949
a(n) is the largest m such that n-m and n+m are both primes, or -1 if no such m exists.
7
0, 0, 1, 2, 1, 4, 5, 4, 7, 8, 7, 10, 9, 8, 13, 14, 13, 12, 17, 16, 19, 20, 19, 22, 21, 20, 25, 24, 23, 28, 29, 28, 27, 32, 31, 34, 35, 34, 33, 38, 37, 40, 39, 38, 43, 42, 41, 30, 47, 46, 49, 50, 49, 52, 53, 52, 55, 54, 53, 48, 51, 50, 45, 62, 61, 64, 63, 62, 67, 68, 67, 66
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
OEIS (Plot 2), A067076 vs A098090 (n-m=3). - Jason Kimberley, Oct 01 2012
FORMULA
a(n) = n - A020481(n).
a(n) = (A020482(n) - A020481(n))/2. - Gionata Neri, Apr 15 2015
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
Cf. A020481.
Cf. A010051.
Sequence in context: A165050 A165042 A165046 * A222986 A222906 A359900
KEYWORD
easy,nice,nonn
AUTHOR
EXTENSIONS
Corrected by Harvey P. Dale, Dec 21 2000
STATUS
approved