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.
%I A380788 #21 Feb 07 2025 05:23:51 %S A380788 2,3,4,5,6,7,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,64,65,66, %T A380788 67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89, %U A380788 90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106 %N A380788 Numbers with a prime number of binary digits. %H A380788 Michael S. Branicky, <a href="/A380788/b380788.txt">Table of n, a(n) for n = 1..10000</a> %e A380788 4 is a term since its binary representation has 3 bits, a prime. %e A380788 64 is a term since its binary representation has 7 bits, a prime. %t A380788 Select[Range[200], PrimeQ[BitLength[#]] &] (* _Paolo Xausa_, Feb 03 2025 *) %o A380788 (Python) %o A380788 from sympy import isprime %o A380788 def ok(n): return isprime(n.bit_length()) %o A380788 print([k for k in range(150) if ok(k)]) %o A380788 (Python) # faster for initial segment of sequence %o A380788 from itertools import islice %o A380788 from sympy import isprime, nextprime %o A380788 def agen(): # generator of terms %o A380788 d = 2 %o A380788 while True: %o A380788 yield from (i for i in range(2**(d-1), 2**d)) %o A380788 d = nextprime(d) %o A380788 print(list(islice(agen(), 65))) %o A380788 (Python) %o A380788 from sympy import primerange %o A380788 def A380788(n): %o A380788 def bisection(f,kmin=0,kmax=1): %o A380788 while f(kmax) > kmax: kmax <<= 1 %o A380788 kmin = kmax >> 1 %o A380788 while kmax-kmin > 1: %o A380788 kmid = kmax+kmin>>1 %o A380788 if f(kmid) <= kmid: %o A380788 kmax = kmid %o A380788 else: %o A380788 kmin = kmid %o A380788 return kmax %o A380788 def f(x): return n+x-sum(min(x,(1<<i)-1)-(1<<i-1)+1 for i in primerange(2,x.bit_length()+1)) %o A380788 return bisection(f,n,n) # _Chai Wah Wu_, Feb 03 2025 %Y A380788 Cf. A272441, A053738. %K A380788 nonn,base,easy %O A380788 1,1 %A A380788 _Michael S. Branicky_, Feb 03 2025