%I #47 Jan 10 2022 06:52:22
%S 1,2,4,9,18,37,74,149,299,599,1198,2397,4794,9589,19179,38359,76718,
%T 153437,306874,613749,1227499,2454999,4909998,9819997,19639995,
%U 39279991,78559983,157119967,314239934,628479869,1256959738,2513919477,5027838955,10055677911
%N a(1)=1, then a(n)=2*a(n-1) if n is prime, a(n)=2*a(n-1)+1 if n not prime.
%C In base 2 a(n) is the concatenation for i=1 to n of A005171(i).
%H Michael S. Branicky, <a href="/A118255/b118255.txt">Table of n, a(n) for n = 1..3322</a> (terms 1..1000 from Harvey P. Dale)
%F a(n) = floor(k * 2^n) where k = 0.585317... = 1 - A051006. [_Charles R Greathouse IV_, Dec 27 2011]
%F From _Ridouane Oudra_, Aug 26 2019: (Start)
%F a(n) = 2^n - 1 - (1/2)*(pi(n) + Sum_{i=1..n} 2^(n-i)*pi(i)), where pi = A000720
%F a(n) = A000225(n) - A072762(n). (End)
%e a(2) = 2*1 = 2 as 2 is prime;
%e a(3) = 2*2 = 4 as 3 is prime;
%e a(4) = 2*4+1 = 9 as 4 is composite;
%e a(5) = 2*9 = 18 as 5 is prime.
%p f:=proc(n) option remember; if n=1 then RETURN(1); fi; if isprime(n) then 2*f(n-1) else 2*f(n-1)+1; fi; end; # _N. J. A. Sloane_
%t nxt[{n_,a_}]:={n+1,If[PrimeQ[n+1],2a,2a+1]}; Transpose[NestList[nxt,{1,1},40]][[2]] (* _Harvey P. Dale_, Jan 22 2015 *)
%t Array[FromDigits[#, 2] &@ Array[Boole[! PrimeQ@ #] &, #] &, 34] (* _Michael De Vlieger_, Nov 01 2016 *)
%o (Python)
%o from sympy import isprime, prime
%o def a(n): return int("".join(str(1-isprime(i)) for i in range(1, n+1)), 2)
%o print([a(n) for n in range(1, 35)]) # _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 yield an
%o print(list(islice(agen(), 34))) # _Michael S. Branicky_, Jan 10 2022
%Y Cf. A000225, A005171, A051006, A072762, A118256, A118257.
%K nonn
%O 1,2
%A _Pierre CAMI_, Apr 19 2006
%E Corrected by _Omar E. Pol_, Nov 08 2007
%E Corrections verified by _N. J. A. Sloane_, Nov 17 2007