OFFSET
1,2
COMMENTS
a(n) is the decimal representation of A139101(n) interpreted as binary number.
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..468
FORMULA
a(n) = A139104(n)/2.
EXAMPLE
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.
MAPLE
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
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
seq(A139102(n), n=1..35) ; # R. J. Mathar, Apr 25 2008
MATHEMATICA
Table[ sum = 0; For[i = 1, i <= Prime[n] - 1 , i++, sum = sum*2;
If[! PrimeQ[i], sum++]]; sum, {n, 1, 25}] (* Robert Price, Apr 03 2019 *)
PROG
(PARI) a(n) = fromdigits(vector(prime(n)-1, k, !isprime(k)), 2); \\ Michel Marcus, Apr 04 2019
(Python)
from sympy import isprime, prime
def a(n):
return int("".join(str(1-isprime(i)) for i in range(1, prime(n))), 2)
print([a(n) for n in range(1, 22)]) # Michael S. Branicky, Jan 10 2022
(Python) # faster version for initial segment of sequence
from sympy import isprime
from itertools import count, islice
def agen(): # generator of terms
an = 0
for k in count(1):
an = 2 * an + int(not isprime(k))
if isprime(k+1):
yield an
print(list(islice(agen(), 21))) # Michael S. Branicky, Jan 10 2022
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Omar E. Pol, Apr 08 2008
EXTENSIONS
More terms from R. J. Mathar, Apr 25 2008
a(20)-a(21) from Robert Price, Apr 03 2019
STATUS
approved