login
Numbers whose binary representation shows the distribution of prime numbers up to the n-th prime minus 1, using "0" for primes and "1" for nonprime numbers.
10

%I #25 Jan 10 2022 06:52:42

%S 1,2,9,37,599,2397,38359,153437,2454999,157119967,628479869,

%T 40222711647,643563386359,2574253545437,41188056726999,

%U 2636035630527967,168706280353789919,674825121415159677,43188807770570219359,691020924329123509751,2764083697316494039005

%N Numbers whose binary representation shows the distribution of prime numbers up to the n-th prime minus 1, using "0" for primes and "1" for nonprime numbers.

%C a(n) is the decimal representation of A139101(n) interpreted as binary number.

%H Michael S. Branicky, <a href="/A139102/b139102.txt">Table of n, a(n) for n = 1..468</a>

%H Omar E. Pol, <a href="http://polprimos.com">Determinacion geometrica de los numeros primos y perfectos</a>.

%F a(n) = A139104(n)/2.

%e a(4)=37 because 37 written in base 2 is 100101 and the string "100101" shows the distribution of prime numbers up to the 4th prime minus 1, using "0" for primes and "1" for nonprime numbers.

%p A139101 := proc(n) option remember ; local a,p; if n = 1 then RETURN(1); else a := 10*A139101(n-1) ; for p from ithprime(n-1)+1 to ithprime(n)-1 do a := 10*a+1 ; od: fi ; RETURN(a) ; end: # _R. J. Mathar_, Apr 25 2008

%p bin2dec := proc(n) local nshft ; nshft := convert(n,base,10) ; add(op(i,nshft)*2^(i-1),i=1..nops(nshft) ) ; end: # _R. J. Mathar_, Apr 25 2008

%p A139102 := proc(n) bin2dec(A139101(n)) ; end: # _R. J. Mathar_, Apr 25 2008

%p seq(A139102(n),n=1..35) ; # _R. J. Mathar_, Apr 25 2008

%t Table[ sum = 0; For[i = 1, i <= Prime[n] - 1 , i++, sum = sum*2;

%t If[! PrimeQ[i], sum++]]; sum, {n, 1, 25}] (* _Robert Price_, Apr 03 2019 *)

%o (PARI) a(n) = fromdigits(vector(prime(n)-1, k, !isprime(k)), 2); \\ _Michel Marcus_, Apr 04 2019

%o (Python)

%o from sympy import isprime, prime

%o def a(n):

%o return int("".join(str(1-isprime(i)) for i in range(1, prime(n))), 2)

%o print([a(n) for n in range(1, 22)]) # _Michael S. Branicky_, Jan 10 2022

%o (Python) # faster version for initial segment of sequence

%o from sympy import isprime

%o from itertools import count, islice

%o def agen(): # generator of terms

%o an = 0

%o for k in count(1):

%o an = 2 * an + int(not isprime(k))

%o if isprime(k+1):

%o yield an

%o print(list(islice(agen(), 21))) # _Michael S. Branicky_, Jan 10 2022

%Y Subset of A118255.

%Y Cf. A000040, A018252, A139101, A139103, A139104, A139119, A139120, A139122.

%K nonn,base

%O 1,2

%A _Omar E. Pol_, Apr 08 2008

%E More terms from _R. J. Mathar_, Apr 25 2008

%E a(20)-a(21) from _Robert Price_, Apr 03 2019