A154734 Define k(0) = 2 and k(m) = m^2-k(m-1) for m >= 1. This is a list of those terms k(m) for which k(m)+1 and k(m)-1 are both in A008578 (primes including 1).
2, 4, 12, 138, 822, 2082, 3918, 21738, 39342, 62130, 70878, 106032, 117372, 129288, 135462, 182712, 512580, 524802, 575130, 682698, 769422, 799482, 893118, 1008912, 1026030, 1043292, 1828830, 2368578, 2447580, 3247428, 3278082, 3465030, 4022868, 4056978
Offset: 1
Keywords
Programs
-
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
-
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
Formula
k(n) = n*(n+1)/2+2*(-1)^n. - Peter Luschny, Jul 14 2022
Extensions
Better name from Pontus von Brömssen, Jul 14 2022
Comments