login
Least k such that prime(n)^2 + k^2 is prime, or 0 if none.
7

%I #21 Mar 22 2019 11:04:14

%S 1,2,2,2,4,2,2,6,8,4,4,2,4,8,2,10,6,10,2,6,2,4,18,4,2,10,2,10,4,18,8,

%T 16,2,10,14,4,10,2,2,10,4,6,4,2,8,16,4,18,8,4,2,10,16,14,18,8,10,6,2,

%U 4,8,2,2,4,2,2,6,20,2,14,8,10,8,2,6,12,4,18,4,6,14,4,6,12,4,28,10,12,6,2,12,14,2,6,4,2,14,14,10,6

%N Least k such that prime(n)^2 + k^2 is prime, or 0 if none.

%C The main entry for this sequence is A240130.

%C k and p_n must be of opposite parity. Conjecture, there is always a k for any p_n. Tested for all primes < 15*10^10. - _Robert G. Wilson v_, Nov 04 2015

%C Least k > 0 for which prime(n)+i*k is a Gaussian prime. - _Robert Israel_, Nov 04 2015

%H Robert Israel, <a href="/A240131/b240131.txt">Table of n, a(n) for n = 1..10000</a>

%F a(n)^2 = A240130(n) - prime(n)^2 if a(n) > 0.

%e Prime(3) = 5 and 5^2 + 1^2 = 26 is not prime but 5^2 + 2^2 = 29 is prime, so a(3) = 2.

%p f:= proc(p) local k; for k from 2 by 2 do if isprime(p^2 + k^2) then return k fi eod nd proc:

%p f(2):= 1:

%p map(f, select(isprime, [2,seq(2*i+1,i=1..10000)])); # _Robert Israel_, Nov 04 2015

%t f[n_] := Block[{k = If[n == 1, 1, 2], p = Prime@ n}, While[ !PrimeQ[k^2 + p^2], k += 2]; k]; Array[f, 100] (* _Robert G. Wilson v_, Nov 03 2015 *)

%t lk[n_]:=Module[{k=2,n2=n^2},While[!PrimeQ[n2+k^2],k+=2];k]; Join[{1}, Table[ lk[x],{x,Prime[Range[2,100]]}]] (* _Harvey P. Dale_, Mar 22 2019 *)

%o (PARI) vector(100, n, p = prime(n); k = 1 - p%2; inc = 2; while (!isprime(q=p^2+k^2), k += inc); k; ) \\ _Altug Alkan_, Nov 04 2015

%Y Cf. A240130.

%K nonn

%O 1,2

%A _Jonathan Sondow_, Apr 07 2014