OFFSET
1,1
COMMENTS
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..10000
James S. DeArmon, Common LISP code for A373581
EXAMPLE
Terms 1,2,and 3 are 3,7,31, with respective base-2 valuations of 11, 111, 11111. The fourth term, 73, is the smallest term containing zeros in the base-2 representation: 1001001. Note the middle bit is shared by both halves; the nested palindrome is "1001".
PROG
(Python)
import sympy
def ispal(n):
return str(n) == str(n)[::-1]
def isodd(n): return n%2
outVec = []
for n in range(9999999):
if not sympy.isprime(n): continue
binStr = (bin(n))[2:]
if not ispal(binStr): continue
lenB = len(binStr)
halfB = int(lenB/2)
if isodd(lenB): halfB += 1
if not ispal(binStr[:halfB]): continue
print(n, binStr)
outVec.append(n)
print(outVec)
(Python)
from sympy import isprime
from itertools import count, islice, product
def pals(d, base=10): # returns a string
digits = "".join(str(i) for i in range(base))
for p in product(digits, repeat=d//2):
if d//2 > 0 and p[0] == "0": continue
left = "".join(p); right = left[::-1]
for mid in [[""], digits][d%2]:
yield left + mid + right
def nbp_gen(): # generator of nested binary palindromes (as strings)
yield '0'
for d in count(1):
yield from (p+p[-1-d%2::-1] for p in pals((d+1)//2, base=2))
def agen(): # generator of terms
yield from filter(isprime, (int(nbp, 2) for nbp in nbp_gen()))
print(list(islice(agen(), 36))) # Michael S. Branicky, Jun 12 2024
(Common LISP) ; See LINKS section.
CROSSREFS
KEYWORD
nonn,base
AUTHOR
James S. DeArmon, Jun 10 2024
STATUS
approved