cp's OEIS Frontend

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.

Showing 1-1 of 1 results.

A380786 Numbers with a prime number of bits, prime number of ones, and prime number of zeros in their binary representation.

Original entry on oeis.org

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

Views

Author

Marc Morgenegg, Feb 03 2025

Keywords

Comments

Each term has either two zeros or two ones in its binary representation. And so the total number of bits of each term is the larger prime of a twin prime pair.

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.
		

Crossrefs

Intersection of A052294, A144754, and A380788.
Subsequence of primes gives A272478.
Subsequence of A343258.
Cf. A006512 (bitlengths of terms).

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
    
Showing 1-1 of 1 results.