login
a(n) is the smallest prime p such that p-n is a nonzero square.
3

%I #35 Feb 06 2019 11:29:48

%S 2,3,7,5,41,7,11,17,13,11,47,13,17,23,19,17,53,19,23,29,37,23,59,73,

%T 29,107,31,29,173,31,47,41,37,43,71,37,41,47,43,41,617,43,47,53,61,47,

%U 83,73,53,59,67,53,89,79,59,137,61,59,383,61,97,71,67,73,101,67,71,149,73

%N a(n) is the smallest prime p such that p-n is a nonzero square.

%H Zak Seidov, <a href="/A059843/b059843.txt">Table of n, a(n) for n = 1..10000</a>

%F a(n) = min{p : p - n = x^2 for some x > 0, p is prime}.

%F Does a(n) exist for all n? - _Jianing Song_, Feb 04 2019

%e 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.

%p SearchLimit := 100;

%p for n from 1 to 400 do

%p k := 0: c := true:

%p while(c and k < SearchLimit) do

%p k := k + 1:

%p c := not isprime(k^2+n):

%p end do:

%p if k = SearchLimit then error("Search limit reached!") fi;

%p a[n] := k^2 + n end do: seq(a[j], j=1..400);

%p # Edited and SearchLimit introduced by _Peter Luschny_, Feb 05 2019

%t spsq[n_]:=Module[{p=NextPrime[n]},While[!IntegerQ[Sqrt[p-n]],p= NextPrime[ p]];p]; Array[spsq,70] (* _Harvey P. Dale_, Nov 10 2017 *)

%o (PARI) for(n=1, 100, for(k=1, 100, if(isprime(k^2+n), print1(k^2+n, ", "); break()))) \\ _Jianing Song_, Feb 04 2019

%o (PARI) a(n) = forprime(p=n,, if ((p-n) && issquare(p-n), return (p))); \\ _Michel Marcus_, Feb 05 2019

%Y These terms arise in A002496, A056899, A049423, A005473, A056905, A056909 as first or 2nd entries depending on offset.

%Y Cf. A002496, A056899, A049423, A005473, A056905, A056909.

%Y Cf. A056896 (where p-n can be 0).

%K nonn

%O 1,1

%A _Labos Elemer_, Feb 26 2001