login
a(n) is the least positive integer such that n^2 + a(n)^2 and n^2 + (a(n) + 2)^2 are primes.
3

%I #50 Aug 15 2024 12:15:16

%S 2,1,8,9,2,29,8,3,14,1,4,23,8,9,2,29,8,5,14,1,44,13,18,59,4,9,20,13,4,

%T 11,4,3,188,9,16,149,28,13,44,1,44,23,8,19,14,19,8,35,4,17,14,3,10,59,

%U 4,9,50,3,24,29,24,43,38,9,2,89,18,5,194,17,14,5

%N a(n) is the least positive integer such that n^2 + a(n)^2 and n^2 + (a(n) + 2)^2 are primes.

%C z = n + i*a(n) and z' = n + i*(a(n) + 2) are two Gaussian primes such that |z - z'| = 2, corresponding to twin primes.

%H Robert Israel, <a href="/A284211/b284211.txt">Table of n, a(n) for n = 1..10000</a> (first 99 terms from Lars-Erik Svahn)

%H Lars-Erik Svahn, <a href="https://github.com/Lehs/ANS-Forth-libraries">numbertheory.4th</a>

%H Akshaa Vatwani, <a href="http://dx.doi.org/10.1016/j.jnt.2016.07.008">Bounded gaps between Gaussian primes</a>, J. of Number Theory 171 (2017), 449-473.

%e a(1)=2: 1^2 + 1^2 = 2 is a prime but 1 + (1 + 2)^2 = 10 is not, while 1^2 + 2^2 = 5 and 1^2 + (2+2)^2 = 17 are both primes.

%p f:= proc(n) local k,pp,p;

%p pp:= false;

%p for k from (n+1) mod 2 by 2 do

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

%p if p and pp then return k-2 fi;

%p pp:= p;

%p od;

%p end proc:

%p map(f, [$1..100]); # _Robert Israel_, Mar 30 2017

%t a[n_] := Block[{k = Mod[n, 2] + 1}, While[! PrimeQ[n^2 + k^2] || ! PrimeQ[n^2 + (k + 2)^2], k += 2]; k]; Array[a, 72] (* _Giovanni Resta_, Mar 23 2017 *)

%t lpi[n_]:=Module[{k=1},While[!AllTrue[n^2+{k^2,(k+2)^2},PrimeQ],k++];k]; Array[lpi,80] (* _Harvey P. Dale_, Aug 15 2024 *)

%o (ANS-Forth)

%o s" numbertheory.4th" included

%o : Gauss_twins \ n -- a(n)

%o dup * locals| square | 0

%o begin 1+ dup dup * square + isprime

%o over 2 + dup * square + isprime and

%o until ;

%o (PARI) a(n) = my(k=n%2+1); while (!(isprime(n^2+k^2) && isprime(n^2+(k+2)^2)), k+=2); k \\ _Michel Marcus_, Mar 25 2017

%Y Cf. A069003.

%K nonn

%O 1,1

%A _Lars-Erik Svahn_, Mar 23 2017