OFFSET
1,5
FORMULA
From Jon E. Schoenfield, Sep 22 2021: (Start)
a(n) = (A343730(2*n) - 1)/2. (End)
EXAMPLE
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)
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 *)
PROG
(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))
(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
CROSSREFS
KEYWORD
nonn
AUTHOR
Lothar Esser, Sep 22 2021
EXTENSIONS
More terms from Michel Marcus, Sep 24 2021
STATUS
approved