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.

A300817 Smallest prime p such that p + n^2 is prime, or 0 if no such prime exists.

Original entry on oeis.org

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
Offset: 0

Views

Author

Bruno Berselli, Mar 13 2018

Keywords

Comments

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

Examples

			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.
		

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.

Programs

  • 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
    
  • 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 *)
  • 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
  • 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