login
A144752
Positive integers whose binary representation is a palindrome and has a prime number of 0's.
2
9, 17, 21, 45, 51, 65, 85, 93, 99, 107, 189, 219, 231, 257, 297, 325, 365, 381, 387, 427, 443, 455, 471, 765, 891, 951, 975, 1105, 1161, 1241, 1285, 1365, 1421, 1501, 1533, 1539, 1619, 1675, 1755, 1787, 1799, 1879, 1911, 1935, 1967, 3069, 3579, 3831, 3951
OFFSET
1,1
COMMENTS
Each term of this sequence is in both sequence A006995 and sequence A144754.
LINKS
EXAMPLE
17 in binary is 10001. This binary representation is a palindrome, it contains three 0's, and three is a prime. So 17 is a term.
PROG
(Python)
from sympy import isprime
def ok(n): b = bin(n)[2:]; return b == b[::-1] and isprime(b.count('0'))
print(list(filter(ok, range(4000)))) # Michael S. Branicky, Sep 17 2021
(Python) # faster for computing initial segment of sequence
from sympy import isprime
from itertools import product
def ok2(bin_str): return isprime(bin_str.count("0"))
def bin_pals(maxdigits):
yield from "01"
digits, midrange = 2, [[""], ["0", "1"]]
for digits in range(2, maxdigits+1):
for p in product("01", repeat=digits//2-1):
left = "1"+"".join(p)
for middle in midrange[digits%2]:
yield left + middle + left[::-1]
def auptopow2(e): return [int(b, 2) for b in filter(ok2, bin_pals(e))]
print(auptopow2(12)) # Michael S. Branicky, Sep 17 2021
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Leroy Quet, Sep 20 2008
EXTENSIONS
Extended by Ray Chandler, Nov 04 2008
Name edited by Michael S. Branicky, Sep 17 2021
STATUS
approved