login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

Smallest k>0 such that n +/- k and n^2 +/- k are all prime. a(n) = 0 if no such number exists.
2

%I #16 Mar 13 2014 07:46:25

%S 0,0,0,0,0,0,0,3,2,3,0,5,0,3,2,0,0,13,12,0,2,0,0,0,6,15,10,0,12,0,0,

%T 15,20,0,12,5,0,15,22,21,12,0,0,0,14,27,0,35,0,0,8,15,0,0,24,27,0,0,

%U 48,7,48,0,50,3,6,7,0,0,28,0,18,0,0,27,34

%N Smallest k>0 such that n +/- k and n^2 +/- k are all prime. a(n) = 0 if no such number exists.

%C a(n) is always smaller than n due to the requirement on n-k.

%H Giovanni Resta, <a href="/A239146/b239146.txt">Table of n, a(n) for n = 1..10000</a>

%e 8 +/- 1 (7 and 9) and 8^2 +/- 1 (63 and 65) are not all prime. 8 +/- 2 (6 and 10) and 8^2 +/- 2 (62 and 66) are not all prime. However, 8 +/- 3 (5 and 11) and 8^2 +/- 3 (61 and 67) are all prime. Thus, a(8) = 3.

%p A239146 := proc(n)

%p local k ;

%p for k from 1 do

%p if n-k <= 1 then

%p return 0;

%p end if;

%p if isprime(n+k) and isprime(n-k) and isprime(n^2+k)

%p and isprime(n^2-k) then

%p return k;

%p end if;

%p end do;

%p end proc:

%p seq(A239146(n),n=1..80) ; # _R. J. Mathar_, Mar 12 2014

%t a[n_] := Catch@ Block[{k = 1}, While[k < n, And @@ PrimeQ@ {n+k, n-k, n^2+k, n^2-k} && Throw@k; k++]; 0]; Array[a, 75] (* _Giovanni Resta_, Mar 13 2014 *)

%o (Python)

%o import sympy

%o from sympy import isprime

%o def c(n):

%o ..for k in range(1,n):

%o ....if isprime(n+k) and isprime(n-k) and isprime(n**2+k) and isprime(n**2-k):

%o ......return k

%o n = 1

%o while n < 100:

%o ..if c(n) == None:

%o ....print(0)

%o ..else:

%o ....print(c(n))

%o ..n += 1

%Y Cf. A082467, A172990, A172989.

%K nonn

%O 1,8

%A _Derek Orr_, Mar 11 2014