A272441 Primes with a prime number of binary digits.
2, 3, 5, 7, 17, 19, 23, 29, 31, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223
Offset: 1
Examples
7 is a term since its binary representation has 3 bits, a prime. 67 is a term since its binary representation has 7 bits, a prime.
Links
- Alois P. Heinz, Table of n, a(n) for n = 1..20000
Crossrefs
Cf. A120533 (analogous in base 10).
Programs
-
Mathematica
Select[Table[j, {j, 1, 1200}], (PrimeQ[#] && PrimeQ[Length@IntegerDigits[#, 2]]) &] Select[Prime[Range[200]],PrimeQ[Length[IntegerDigits[#,2]]]&] (* Harvey P. Dale, Jun 04 2019 *)
-
PARI
isok(n) = isprime(n) && isprime(#binary(n)); \\ Michel Marcus, Apr 30 2016
-
PARI
forprime(d=2,13, forprime(p=2^(d-1),2^d, print1(p", "))) \\ Charles R Greathouse IV, May 01 2016
-
Python
from itertools import islice from sympy import isprime, nextprime def agen(): # generator of terms d = 3 yield from [2, 3] while True: yield from (i for i in range(2**(d-1)+1, 2**d, 2) if isprime(i)) d = nextprime(d) print(list(islice(agen(), 50))) # Michael S. Branicky, Dec 27 2023
-
Python
from sympy import primepi, primerange def A272441(n): def bisection(f,kmin=0,kmax=1): while f(kmax) > kmax: kmax <<= 1 kmin = kmax >> 1 while kmax-kmin > 1: kmid = kmax+kmin>>1 if f(kmid) <= kmid: kmax = kmid else: kmin = kmid return kmax def f(x): return n+x-sum(primepi(min(x,(1<Chai Wah Wu, Feb 03 2025