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.

User: Lothar Esser

Lothar Esser's wiki page.

Lothar Esser has authored 2 sequences.

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

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

A273802 Prime numbers formed by successively prepending prime numbers to 3.

Original entry on oeis.org

3, 53, 1153, 311153, 101311153, 271101311153, 347271101311153, 631347271101311153, 719631347271101311153, 829719631347271101311153, 1031829719631347271101311153, 11231031829719631347271101311153, 125911231031829719631347271101311153, 1801125911231031829719631347271101311153
Offset: 1

Author

Lothar Esser, Jun 03 2016

Keywords

Comments

The sequence is related to the existing sequence in which primes are appended so that primes result 2, 23, 2311, 231131, ... (see A240563). The current sequence cannot start with the first prime 2 because it could not be extended since any number > 2 and ending in 2 is a nonprime. So this sequence has to start with 3.
One could also consider analogous sequences starting with any prime greater than 3.
The sequence of primes appended at n-th term is 3, 5, 11, 31, 101, 271, 347, 631, 719, 829, 1031, 1123, 1259, 1801, 1907, 2557, 2591, 2851, 2897, 3301, 3467, 3853, 4157, 4789, 6917, 6991, 7127, 7369, 9767, 13879, 15791, 17239, 19541, 22447, 23663, 25309, 25577, 25873, 29873, 33301, 33713, 34543, 36389, 37159, 39821, 40597, 41453, 41479, 43997, ... - Michael De Vlieger, Jun 03 2016

Examples

			Start with 3 as the first term.
a(2) = 53, since the next prime after a(1) = 3 is 5; 5 prepended to 3 gives 53, another prime.
a(3) = 1153, since the next prime after that appended to a(2), i.e., 5, is 7, however 7 appended to a(2) = 753 = 3 * 251. The next prime 11, appended to a(2) gives us 1153, which is prime.
		

Crossrefs

Cf. A240563.

Programs

  • Mathematica
    a = {3}; Do[p = NextPrime@ a[[n - 1]]; While[! PrimeQ@ FromDigits@ Join[IntegerDigits@ p, Flatten@ Map[IntegerDigits, Reverse@ a]], p = NextPrime@ p]; AppendTo[a, p], {n, 2, 14}]; FoldList[FromDigits@ Join[IntegerDigits@ #2, IntegerDigits@ #1] &, a] (* Michael De Vlieger, Jun 03 2016 *)
  • Python
    from itertools import islice
    from sympy import isprime, nextprime
    def agen(): # generator of terms
        p = an = 3
        while True:
            yield an
            s = str(an)
            while not isprime(int(str(p) + s)): p = nextprime(p)
            an = int(str(p) + s)
    print(list(islice(agen(), 14))) # Michael S. Branicky, Oct 29 2022
  • Tcl
    #! /usr/bin/tclsh
    set prime_list_file list_prime_1000.dat ;
    proc PR_read_primes { fh } {
    global Prime Nprime;
      set idx 0;
      while { ![eof $fh] } {
        gets $fh line;
        foreach p $line {
          set Prime($idx) $p;
          incr idx;
        }
      }
      set Nprime $idx;
    }
    proc PR_is_prime { num } {
      set channel [open "| factor $num r"];
      fconfigure $channel -buffering none;
      set line [read $channel] ;
      #puts "$line [llength $line]";
      if { [llength $line] == 2 } {
        catch { close $channel}
        return 1;
      }
      return 0;
    }
    ### main
    if { ! [catch "open $prime_list_file r" fh ] } {
      PR_read_primes $fh;
      close $fh;
    } else {
        puts "Cannot open file $prime_list_file";
        exit 1
    }
    set t $Prime(1);
    set num_tested_primes 0;
    for { set idx 2 } { $idx < 1000 } { incr idx } {
      # Assemble
      # Simple tests
      set s $Prime($idx)$t;
      if { [PR_is_prime $s] } {
        set t $s;
        puts "$t prepended prime $Prime($idx) skipped $num_tested_primes";
        set num_tested_primes 0;
      } else {
         incr num_tested_primes;
      }
    }
    # The language is Tcl but it requires and external file with the first 1000 primes for convenience. It also uses UNIX program factor as external function to find out whether the number is a prime.