login
This site is supported by donations to The OEIS Foundation.

 

Logo


Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A300817 Smallest prime p such that p + n^2 is prime, or 0 if no such prime exists. 1
2, 2, 3, 2, 3, 0, 5, 0, 3, 2, 3, 0, 5, 0, 3, 2, 7, 0, 7, 0, 19, 2, 3, 0, 11, 0, 7, 0, 3, 0, 7, 0, 7, 2, 7, 0, 5, 0, 3, 2, 7, 0, 13, 0, 13, 2, 13, 0, 5, 0, 3, 0, 3, 0, 11, 0, 31, 2, 7, 0, 7, 0, 3, 0, 3, 0, 7, 0, 13, 0, 3, 0, 5, 0, 3, 0, 3, 0, 5, 0, 73, 2, 13, 0, 13, 0, 37, 0, 13, 0 (list; graph; refs; listen; history; text; internal format)
OFFSET

0,1

COMMENTS

a(n) = 0 if n is a member of A106571.

LINKS

Robert Israel, Table of n, a(n) for n = 0..10000

EXAMPLE

For n = 16:

2 + 16^2 is not prime;

3 + 16^2 = 7*37 is not prime;

5 + 16^2 = 3*87 is not prime;

7 + 16^2 = 263 is prime, therefore a(16) = 7.

MAPLE

A300817 := proc(n) local p, n2; p := 2; n2 := n^2;

    if irem(n2, 2) = 1 and numtheory:-invphi(n2+1) = [] then return 0 fi;

    do if isprime(p + n2) then return p fi; p := nextprime(p) od;

end: seq(A300817(n), n = 0..89); # Peter Luschny, Mar 13 2018

MATHEMATICA

a[n_] := Block[{p=2}, If[OddQ[n], If[PrimeQ[n^2 + 2], 2, 0], While[! PrimeQ[n^2 + p], p = NextPrime[p]]; p]]; a /@ Range[0, 89] (* Giovanni Resta, Mar 13 2018 *)

PROG

(Julia)

using Primes

function A300817(n) p, q = 2, n * n

    n % 2 == 1 && return isprime(p + q) ? 2 : 0

    while !isprime(p + q) p = nextprime(p + 1) end

p end

[A300817(n) for n in 0:89] |> println # Peter Luschny, Mar 13 2018

(Python)

from sympy import nextprime, isprime

def A300817(n):

    p, n2 = 2, n**2

    if n % 2:

        return 2 if isprime(2+n2) else 0

    while not isprime(p+n2):

        p = nextprime(p)

    return p # Chai Wah Wu, Mar 14 2018

(PARI) A300817(n)={if(bittest(n, 0), n=n^2; forprime(p=2, , isprime(2+n)&&return(p)), isprime(2+n^2)*2)} \\ M. F. Hasler, Mar 14 2018

CROSSREFS

Cf. A087242: smallest prime p such that p + n is prime.

Cf. A174960: smallest prime p such that p + n*(n+1)/2 is prime.

Cf. A106571.

Sequence in context: A185268 A279630 A279632 * A230140 A156220 A261653

Adjacent sequences:  A300814 A300815 A300816 * A300818 A300819 A300820

KEYWORD

nonn

AUTHOR

Bruno Berselli, Mar 13 2018

STATUS

approved

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

License Agreements, Terms of Use, Privacy Policy. .

Last modified October 16 09:29 EDT 2019. Contains 328056 sequences. (Running on oeis4.)