OFFSET
1,1
FORMULA
k(n) = n*(n+1)/2+2*(-1)^n. - Peter Luschny, Jul 14 2022
MAPLE
a := proc(n) local k; k := n*(n - 1)/2 - 2*(-1)^n:
if k = 2 or isprime(k - 1) and isprime(k + 1) then k else NULL fi end:
seq(a(n), n = 1..1000); # Peter Luschny, Jul 14 2022
MATHEMATICA
k=2; lst={k}; Do[k=n^2-k; If[PrimeQ[k-1]&&PrimeQ[k+1], AppendTo[lst, k]], {n, 8!}]; lst
PROG
(PARI) a154734(upto, k0=2) = {my(k=k0); print1(k, ", "); for(n=1, oo, my(kk=n^2-k); if(isprime(k-1) && isprime(k+1), print1(k, ", ")); k=kk; if(k>upto, break))};
a154734(5000000) \\ Hugo Pfoertner, Jul 14 2022
CROSSREFS
KEYWORD
nonn
AUTHOR
Vladimir Joseph Stephan Orlovsky, Jan 14 2009
EXTENSIONS
Better name from Pontus von Brömssen, Jul 14 2022
STATUS
approved