A373941 Numbers whose base-2 representation is a "nested" palindrome.
0, 1, 3, 7, 15, 21, 31, 45, 63, 73, 127, 153, 255, 273, 341, 443, 511, 561, 693, 891, 1023, 1057, 1453, 1651, 2047, 2145, 2925, 3315, 4095, 4161, 4681, 5461, 5981, 6371, 6891, 7671, 8191, 8385, 9417, 10965, 11997, 12771, 13803, 15351, 16383, 16513, 19609, 21157
Offset: 1
Examples
45 = 101101_2 is a term, since its base-2 representation is a palindrome, and its right half and left half in base-2 are each the palindrome 101. 73 = 1001001_2 is a term, since its base-2 representation is a palindrome, and its right half and left half (both including the center digit) in base-2 are each the palindrome 1001.
Links
- Michael S. Branicky, Table of n, a(n) for n = 1..10000
Programs
-
PARI
isok(k) = my(b=binary(k), b1=Vec(b, ceil(#b/2)), b2=Vec(Vecrev(b), ceil(#b/2))); (Vecrev(b) == b) && (Vecrev(b1) == b1) && (Vecrev(b2) == b2); \\ Michel Marcus, Jun 26 2024
-
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) for d in count(2): yield from (p+p[-1-d%2::-1] for p in pals((d+1)//2, base=2)) def agen(): # generator of terms yield from [0, 1] yield from (int(nbp, 2) for nbp in nbp_gen() if nbp[0] != "0") print(list(islice(agen(), 46)))
Comments