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
KEYWORD
nonn
AUTHOR
Bruno Berselli, Mar 13 2018
STATUS
approved