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.

Showing 1-1 of 1 results.

A373581 Prime numbers whose base-2 representation is a "nested" palindrome.

Original entry on oeis.org

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

Views

Author

James S. DeArmon, Jun 10 2024

Keywords

Comments

The definition of "nested" palindrome per A344550 is used: both the right and left halves of the base-2 representation of each term are themselves palindromes. "Half" means ceiling(m/2) for a m-bit term. (By contrast, A240601 uses floor(m/2).)

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".
		

Crossrefs

Subsequence of A016041.
Primes in A373941.
Cf. A344550.

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.
Showing 1-1 of 1 results.