A380786 Numbers with a prime number of bits, prime number of ones, and prime number of zeros in their binary representation.
17, 18, 19, 20, 21, 22, 24, 25, 26, 28, 65, 66, 68, 72, 79, 80, 87, 91, 93, 94, 96, 103, 107, 109, 110, 115, 117, 118, 121, 122, 124, 4097, 4098, 4100, 4104, 4112, 4128, 4160, 4224, 4352, 4608, 5119, 5120, 5631, 5887, 6015, 6079, 6111, 6127, 6135, 6139, 6141, 6142, 6144, 6655, 6911
Offset: 1
Examples
a(1) = 17 = 10001_2. Number of bits is 5, number of ones is 2, number of zeros is 3. {2,3,5} are all primes.
Links
- Michael S. Branicky, Table of n, a(n) for n = 1..10000
Crossrefs
Programs
-
Mathematica
Select[Range[2^13], AllTrue[{#1, #2, #1 - #2} & @@ {IntegerLength[#,2], DigitCount[#, 2, 1]}, PrimeQ] & ] (* Michael De Vlieger, Feb 03 2025 *)
-
PARI
isok(k) = my(h=hammingweight(k), b=#binary(k)); isprime(h) && isprime(b) && isprime(b-h); \\ Michel Marcus, Feb 07 2025
-
Python
from sympy import isprime def ok(n): return isprime(L:=n.bit_length()) and isprime(O:=n.bit_count()) and isprime(L-O) print([k for k in range(7160) if ok(k)]) # Michael S. Branicky, Feb 03 2025
-
Python
from sympy import isprime, nextprime, sieve from itertools import combinations, count, islice def agen(): # generator of terms p = 5 while True: passed = set() if isprime(p-2): for q in [2, p-2]: for locs in combinations(range(1, p), q-1): w = ["1"] + ["0"]*(p-1) for i in locs: w[i] = "1" passed.add(int("".join(w), 2)) yield from sorted(passed) p = nextprime(p) print(len(passed), p) print(list(islice(agen(), 61))) # Michael S. Branicky, Feb 03 2025
Comments