A144753 Positive integers whose binary representation is a palindrome and has a prime number of 1's.
3, 5, 7, 9, 17, 21, 31, 33, 65, 73, 93, 107, 127, 129, 257, 273, 313, 341, 381, 403, 443, 471, 513, 1025, 1057, 1137, 1193, 1273, 1317, 1397, 1453, 1571, 1651, 1707, 1831, 2047, 2049, 4097, 4161, 4321, 4433, 4593, 4681, 4841, 4953, 5189, 5349, 5461, 5709
Offset: 1
Examples
21 in binary is 10101. This binary representation is a palindrome, it contains three 1's, and three is a prime. So 21 is a term.
Links
- Indranil Ghosh, Table of n, a(n) for n = 1..11167 (terms 1..1000 from Vincenzo Librandi)
Programs
-
Mathematica
okQ[n_] := Module[{idn2 = IntegerDigits[n, 2]}, (idn2 == Reverse[idn2]) && PrimeQ[First[DigitCount[n, 2]]]];Select[Range[10000], okQ] (* Harvey P. Dale, Sep 23 2008 *)
-
Python
from sympy import isprime def ok(n): b = bin(n)[2:]; return b == b[::-1] and isprime(b.count("1")) print(list(filter(ok, range(5710)))) # 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("1")) 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(13)) # Michael S. Branicky, Sep 17 2021
Extensions
More terms from Harvey P. Dale, Sep 23 2008
Name edited by Michael S. Branicky, Sep 17 2021
Comments