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.

A347986 Length of identical sequence of prime / nonprime numbers left and right of the integer n (excluded).

Original entry on oeis.org

0, 0, 0, 1, 2, 2, 1, 0, 5, 0, 1, 8, 1, 0, 9, 0, 1, 6, 1, 0, 3, 0, 3, 0, 1, 4, 1, 0, 1, 18, 1, 0, 1, 4, 1, 0, 3, 0, 3, 0, 1, 12, 1, 0, 3, 0, 3, 0, 1, 6, 1, 0, 7, 0, 1, 4, 1, 0, 1, 10, 1, 0, 1, 4, 1, 0, 3, 0, 3, 0, 1, 4, 1, 0, 1, 4, 1, 0, 3, 0, 9, 0, 3, 0, 1, 6, 1, 0, 5, 0, 1, 2, 7, 2, 1, 0, 3, 0, 3
Offset: 1

Views

Author

Lothar Esser, Sep 22 2021

Keywords

Examples

			For n=2 (first useful term) the result is 0 because 2 is preceded by 1 which is by definition nonprime and succeeded by 3 which is prime meaning symmetry is broken right away. A better example may be 5 with a value of 2. The two numbers preceding 5 are 3, 4: prime, nonprime and the succeeding values are 6 and 7 being nonprime and prime. In other words, starting from 5 as center, the first positions are 4 (left) and 6 (right), both nonprimes. The next positions are 3 and 7, both primes. The sequence is now 2 long. It breaks after that because 2 is prime but 8 is nonprime. So we note 2 or 5. Very interesting is 30 which has a sequence of 18 on each side that follow the same pattern.
From _Jon E. Schoenfield_, Sep 22 2021: (Start)
As shown in the illustration below, where P and N denote prime and nonprime, respectively, the distribution of primes and nonprimes around n=21 is symmetrical in the interval [18, 24] = [21-3, 21+3], but not in the interval [17, 25] = [21-4, 21+4] (since 17 is prime but 25 is composite), so a(21) = 3:
.
              |<------- 3 -------->|<------- 3 -------->|
      17     18     19     20     21     22     23     24     25
  -----+------+------+------+------+------+------+------+------+-----
       P      N      P      N      N      N      P      N      N
              |      |      |             |      |      |
              |      |      +-------------+      |      |
              |      +---------------------------+      |
              +-----------------------------------------+
(End)
		

Crossrefs

Cf. A343730, A346399 (number of primes in the interval n +- a(n)).

Programs

  • Mathematica
    Table[s={n-1,n+1};k=0;While[SameQ@@PrimeQ@s,k++;s=s+{-1,+1}];k,{n,2,85}] (* Giorgos Kalogeropoulos, Sep 23 2021 *)
  • PARI
    f(n) = {my (nb = 0, fL, fR); fL = n\2; if (n%2, fR = fL+1, fL--; fR = fL+2); for (i=0, oo, if (isprime(fL-i) != isprime(fR+i), break, nb++);); if (n%2, 2*nb, 2*nb+1);} \\ A343730
    a(n) = (f(2*n) - 1)/2; \\ Michel Marcus, Sep 24 2021
  • Python
    from sympy import *
    seq_pole = []
    seq_pole.append(-1) #0
    seq_pole.append(-1) #1
    for i in range(1, 1000):
        d = 1
        #  Check how far the left is identical to the
        # (mirrored) right
        while isprime(i-d) == isprime(i+d):
            d = d + 1
        dmax = d - 1
        seq_pole.append(dmax)
        # i is the center (index) and dmax is the max extent
        # on each side that is the same (or mirrored at i if you will)
        print("{}".format(dmax))
    

Formula

From Jon E. Schoenfield, Sep 22 2021: (Start)
a(n) = Max_{k : A010051(n-j) = A010051(n+j) for 0 <= j <= k}.
a(n) = (A343730(2*n) - 1)/2. (End)

Extensions

More terms from Michel Marcus, Sep 24 2021