OFFSET
1,1
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.
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..10000
EXAMPLE
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.
MATHEMATICA
Select[Range[2^13], AllTrue[{#1, #2, #1 - #2} & @@ {IntegerLength[#, 2], DigitCount[#, 2, 1]}, PrimeQ] & ] (* Michael De Vlieger, Feb 03 2025 *)
PROG
(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
(PARI) isok(k) = my(h=hammingweight(k), b=#binary(k)); isprime(h) && isprime(b) && isprime(b-h); \\ Michel Marcus, Feb 07 2025
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Marc Morgenegg, Feb 03 2025
STATUS
approved