A373581 Prime numbers whose base-2 representation is a "nested" palindrome.
3, 7, 31, 73, 127, 443, 1453, 5981, 8191, 19609, 21157, 28123, 29671, 83269, 131071, 262657, 287281, 324217, 354997, 367309, 431947, 456571, 462727, 499663, 524287, 1348901, 1488301, 1715851, 1875751, 5548693, 6298627, 7331323, 7355911, 8093551, 8191903
Offset: 1
Examples
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".
Links
- Michael S. Branicky, Table of n, a(n) for n = 1..10000
- James S. DeArmon, Common LISP code for A373581
Programs
-
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.
Comments