login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A372517
Least k such that the k-th prime number has exactly n ones in its binary expansion.
13
1, 2, 4, 9, 11, 64, 31, 76, 167, 309, 502, 801, 1028, 7281, 6363, 12079, 12251, 43237, 43390, 146605, 291640, 1046198, 951351, 2063216, 3957778, 11134645, 14198321, 28186247, 54387475, 249939829, 105097565, 393248783, 751545789, 1391572698, 2182112798, 8242984130
OFFSET
1,2
COMMENTS
In other words, the a(n)-th prime is the least with binary weight n. The sorted version is A372686.
FORMULA
A000040(a(n)) = A061712(n).
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
Positions firsts of first appearances in A014499.
Taking primes gives A061712.
Counting zeros (weight) gives A372474, firsts of A035103.
For binary length we have A372684 (take primes A104080), firsts of A035100.
The sorted version is A372686, taking primes A372685.
A000120 counts ones in binary expansion (binary weight), zeros A080791.
A029837 gives greatest binary index, least A001511.
A030190 gives binary expansion, reversed A030308.
A048793 lists binary indices, reverse A272020, sum A029931.
A372471 lists binary indices of primes.
Sequence in context: A292769 A307997 A372686 * A096134 A058885 A256446
KEYWORD
nonn,base
AUTHOR
Gus Wiseman, May 12 2024
EXTENSIONS
a(32)-a(36) from Pontus von Brömssen, May 13 2024
STATUS
approved