OFFSET
1,1
LINKS
Zak Seidov, Table of n, a(n) for n = 1..10000
FORMULA
a(n) = min{p : p - n = x^2 for some x > 0, p is prime}.
Does a(n) exist for all n? - Jianing Song, Feb 04 2019
EXAMPLE
For n = 17, let P = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,...} be the set of primes, then P - 17 = {-15,...,-4,0,2,6,12,14,20,24,26,30,36,...}. The first positive square in P - 17 is 36 with p = 53, so a(17) = 53. The square arising here is usually 1.
MAPLE
SearchLimit := 100;
for n from 1 to 400 do
k := 0: c := true:
while(c and k < SearchLimit) do
k := k + 1:
c := not isprime(k^2+n):
end do:
if k = SearchLimit then error("Search limit reached!") fi;
a[n] := k^2 + n end do: seq(a[j], j=1..400);
# Edited and SearchLimit introduced by Peter Luschny, Feb 05 2019
MATHEMATICA
spsq[n_]:=Module[{p=NextPrime[n]}, While[!IntegerQ[Sqrt[p-n]], p= NextPrime[ p]]; p]; Array[spsq, 70] (* Harvey P. Dale, Nov 10 2017 *)
PROG
(PARI) for(n=1, 100, for(k=1, 100, if(isprime(k^2+n), print1(k^2+n, ", "); break()))) \\ Jianing Song, Feb 04 2019
(PARI) a(n) = forprime(p=n, , if ((p-n) && issquare(p-n), return (p))); \\ Michel Marcus, Feb 05 2019
CROSSREFS
KEYWORD
nonn
AUTHOR
Labos Elemer, Feb 26 2001
STATUS
approved