OFFSET
1,1
COMMENTS
a(12) < 1294268635 is the first term where the first formula is a strict inequality. - Michael S. Branicky, Apr 22 2022
FORMULA
a(n) <= A000230(n^2) + n^2. - David A. Corneth, May 02 2022
a(n) = A282690(n^2). - Michel Marcus, Jul 10 2022
EXAMPLE
a(1) = 4, because 3 and 5 are the prime neighbors of 4, and 5 - 4 = 4 - 3 = 1 = 1^2 and no number less than 4 differs from both of its prime neighbors by 1^2.
a(2) = 93, because 97 and 89 are the prime neighbors of 93, and 97 - 93 = 93 - 89 = 4 = 2^2 and no number less than 93 differs from both of its prime neighbors by 2^2.
MATHEMATICA
a[n_] := a[n] = Module[{diff, diff2, p, q, r},
{diff, diff2, p} = {n*n, 2*n*n, NextPrime[1 + n^2]};
q = NextPrime[p];
r = NextPrime[q];
While[!(q - p == diff2 || (q - p == diff && r - q == diff)),
{p, q, r} = {q, r, NextPrime[r]}];
Return[If[q - p == diff2, Floor[(q + p)/2], q]]];
Table[Print[n, " ", a[n]]; a[n], {n, 1, 10}] (* Jean-François Alcover, Jun 07 2022, after Michael S. Branicky's code *)
PROG
(Python)
from sympy import nextprime
def a(n):
diff, diff2, p = n*n, 2*n*n, nextprime(1+n**2)
q = nextprime(p)
r = nextprime(q)
while not (q-p == diff2 or (q-p == diff and r-q == diff)):
p, q, r = q, r, nextprime(r)
return (q+p)//2 if q-p == diff2 else q
print([a(n) for n in range(1, 9)]) # Michael S. Branicky, Apr 22 2022
(PARI) a(n) = my(k=2); while (((nextprime(k+1)-k) != n^2) || ((k-precprime(k-1)) != n^2), k++); k; \\ Michel Marcus, Jul 10 2022
CROSSREFS
KEYWORD
nonn,more
AUTHOR
Jean-Marc Rebert, Apr 22 2022
EXTENSIONS
a(13) from Michael S. Branicky, Apr 24 2022
STATUS
approved