login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A243145 Least positive number k such that n+k and n+k^2 are both prime. 3

%I #19 Sep 03 2019 17:48:08

%S 1,1,2,1,6,1,4,3,2,1,6,1,4,3,2,1,6,1,12,3,16,1,6,7,4,15,2,1,12,1,6,9,

%T 8,3,6,1,4,3,2,1,30,1,4,3,8,1,6,5,10,3,10,1,6,5,4,15,2,1,42,1,6,21,4,

%U 3,6,1,4,15,2,1,30,1,6,33,8,25,6,1,10,3,16,1,24,5,4,15

%N Least positive number k such that n+k and n+k^2 are both prime.

%C For n > 1, a(n) == n+1 (mod 2). a(n) = 1 for n in A006093. - _Robert Israel_, Feb 02 2018

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

%e 8+1 and 8+1^2 (9) isn't prime. 8+2 and 8+2^2 (10 and 12) aren't both prime. But 8+3 and 8+3^2 (11 and 17) are both prime. Thus a(8) = 3.

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

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

%p if isprime(n+k) and isprime(n+k^2) then return k fi

%p od

%p end proc:

%p f(1):= 1:

%p map(f, [$1..100]); # _Robert Israel_, Feb 02 2018

%t f[n_] := Module[{k}, For[k = Mod[n, 2] + 1, True, k += 2, If[PrimeQ[n + k] && PrimeQ[n + k^2], Return[k]]]]; f[1] = 1; f /@ Range[100] (* _Jean-François Alcover_, Feb 03 2018, after _Robert Israel_ *)

%o (PARI) a(n)=for(k=1,10^6,if(ispseudoprime(n+k)&&ispseudoprime(n+k^2),return(k)))

%o n=1;while(n<100,print1(a(n),", ");n+=1)

%o (Python)

%o from sympy import isprime, nextprime

%o def A243145(n):

%o m = n

%o while True:

%o m = nextprime(m)

%o k = m-n

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

%o return k # _Chai Wah Wu_, Sep 03 2019

%Y Cf. A006093.

%K nonn

%O 1,3

%A _Derek Orr_, May 30 2014

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified July 30 16:19 EDT 2024. Contains 374770 sequences. (Running on oeis4.)