login
Numbers k such that nextprime(k)-k is a positive square.
3

%I #21 May 05 2023 20:25:29

%S 1,2,4,6,7,10,12,13,16,18,19,22,25,28,30,33,36,37,40,42,43,46,49,52,

%T 55,58,60,63,66,67,70,72,75,78,79,82,85,88,93,96,97,100,102,103,106,

%U 108,109,112,118,123,126,127,130,133,136,138,140,145,148,150,153

%N Numbers k such that nextprime(k)-k is a positive square.

%C Numbers p-1, where p is prime is a subsequence (see A006093).

%H David A. Corneth, <a href="/A353072/b353072.txt">Table of n, a(n) for n = 1..10000</a>

%e The next prime after 7 is 11, and 11-7 = 4 a square, so 7 is in this sequence.

%e The next prime after 118 is 127, 127-118 = 9 is a square, so 118 is a term.

%t Select[Range[2000], NextPrime[#] - # > 0 && IntegerQ[Sqrt[NextPrime[#] - #]] &]

%t npsQ[n_]:=With[{c=NextPrime[n]-n},c>0&&IntegerQ[Sqrt[c]]]; Select[Range[200],npsQ] (* _Harvey P. Dale_, May 05 2023 *)

%o (PARI) upto(n) = {my(res = List(1), q = 2, u = nextprime(n + 1)); forprime(p = 3, u, forstep(i = sqrtint(p - q), 1, -1, listput(res, p-i^2) ); q = p ); res } \\ _David A. Corneth_, Apr 22 2022

%o (PARI) isok(k) = issquare(nextprime(k+1)-k); \\ _Michel Marcus_, Apr 22 2022

%Y Cf. A006093, A013632, A029710.

%K nonn

%O 1,2

%A _Tanya Khovanova_, Apr 21 2022