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.

Showing 1-2 of 2 results.

A087242 Smallest prime number p such that n+p = q is also a prime, or 0 if no such prime number exists.

Original entry on oeis.org

2, 3, 2, 3, 2, 5, 0, 3, 2, 3, 2, 5, 0, 3, 2, 3, 2, 5, 0, 3, 2, 7, 0, 5, 0, 3, 2, 3, 2, 7, 0, 5, 0, 3, 2, 5, 0, 3, 2, 3, 2, 5, 0, 3, 2, 7, 0, 5, 0, 3, 2, 7, 0, 5, 0, 3, 2, 3, 2, 7, 0, 5, 0, 3, 2, 5, 0, 3, 2, 3, 2, 7, 0, 5, 0, 3, 2, 5, 0, 3, 2, 7, 0, 5, 0, 3, 2, 13, 0, 7, 0, 5, 0, 3, 2, 5, 0, 3, 2, 3, 2, 5, 0, 3, 2
Offset: 1

Views

Author

Labos Elemer, Sep 04 2003

Keywords

Examples

			a(n)=0, i.e., no solution exists if n is a special prime, namely n is not a lesser twin prime; e.g., if n=7, then neither 7+2=9 nor 7+(odd prime) is a prime, thus no p prime exists such that 7+p is also a prime.
If n is a lesser twin prime then a(n)=2 is a solution because n+a(n) = n+2 = greater twin prime satisfying the condition.
		

Crossrefs

Programs

  • PARI
    a(n) = {if (n % 2, if (isprime(n+2), p = 2, p = 0);, p = 2; while (!isprime(n+p), p = nextprime(p+1));); p;} \\ Michel Marcus, Dec 26 2013

Formula

a(n) = Min{x prime; n+x is prime}.

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
    
Showing 1-2 of 2 results.