cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

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

This page as a plain text file.
%I A239146 #19 Mar 21 2025 18:34:22
%S A239146 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 A239146 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 A239146 48,7,48,0,50,3,6,7,0,0,28,0,18,0,0,27,34
%N A239146 Smallest k>0 such that n +/- k and n^2 +/- k are all prime. a(n) = 0 if no such number exists.
%C A239146 a(n) is always smaller than n due to the requirement on n-k.
%H A239146 Giovanni Resta, <a href="/A239146/b239146.txt">Table of n, a(n) for n = 1..10000</a>
%e A239146 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 A239146 := proc(n)
%p A239146     local k ;
%p A239146     for k from 1 do
%p A239146         if n-k <= 1 then
%p A239146             return 0;
%p A239146         end if;
%p A239146         if isprime(n+k) and isprime(n-k) and isprime(n^2+k)
%p A239146             and isprime(n^2-k) then
%p A239146             return k;
%p A239146         end if;
%p A239146     end do;
%p A239146 end proc:
%p A239146 seq(A239146(n),n=1..80) ; # _R. J. Mathar_, Mar 12 2014
%t A239146 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 A239146 (Python)
%o A239146 import sympy
%o A239146 from sympy import isprime
%o A239146 def c(n):
%o A239146   for k in range(1,n):
%o A239146     if isprime(n+k) and isprime(n-k) and isprime(n**2+k) and isprime(n**2-k):
%o A239146       return k
%o A239146 n = 1
%o A239146 while n < 100:
%o A239146   if c(n) == None:
%o A239146     print(0)
%o A239146   else:
%o A239146     print(c(n))
%o A239146   n += 1
%Y A239146 Cf. A082467, A172990, A172989.
%K A239146 nonn
%O A239146 1,8
%A A239146 _Derek Orr_, Mar 11 2014