OFFSET
1,2
COMMENTS
In other words, the a(n)-th prime is the least with binary weight n. The sorted version is A372686.
EXAMPLE
The primes A000040(a(n)) together with their binary expansions and binary indices begin:
2: 10 ~ {2}
3: 11 ~ {1,2}
7: 111 ~ {1,2,3}
23: 10111 ~ {1,2,3,5}
31: 11111 ~ {1,2,3,4,5}
311: 100110111 ~ {1,2,3,5,6,9}
127: 1111111 ~ {1,2,3,4,5,6,7}
383: 101111111 ~ {1,2,3,4,5,6,7,9}
991: 1111011111 ~ {1,2,3,4,5,7,8,9,10}
2039: 11111110111 ~ {1,2,3,5,6,7,8,9,10,11}
3583: 110111111111 ~ {1,2,3,4,5,6,7,8,9,11,12}
6143: 1011111111111 ~ {1,2,3,4,5,6,7,8,9,10,11,13}
8191: 1111111111111 ~ {1,2,3,4,5,6,7,8,9,10,11,12,13}
73727: 10001111111111111 ~ {1,2,3,4,5,6,7,8,9,10,11,12,13,17}
63487: 1111011111111111 ~ {1,2,3,4,5,6,7,8,9,10,11,13,14,15,16}
MATHEMATICA
spsm[y_]:=Max@@NestWhile[Most, y, Union[#]!=Range[Max@@#]&];
j=DigitCount[#, 2, 1]&/@Select[Range[1000], PrimeQ];
Table[Position[j, k][[1, 1]], {k, spsm[j]}]
PROG
(PARI) a(n) = my(k=1, p=2); while(hammingweight(p) !=n, p = nextprime(p+1); k++); k; \\ Michel Marcus, May 13 2024
(Python)
from itertools import count
from sympy import isprime, primepi
from sympy.utilities.iterables import multiset_permutations
def A372517(n):
for l in count(n-1):
m = 1<<l
for d in multiset_permutations('0'*(l-n+1)+'1'*(n-1)):
k = m+int('0'+''.join(d), 2)
if isprime(k):
return primepi(k) # Chai Wah Wu, May 13 2024
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Gus Wiseman, May 12 2024
EXTENSIONS
a(32)-a(36) from Pontus von Brömssen, May 13 2024
STATUS
approved