%I #18 Nov 21 2019 04:06:00
%S 1,2,1,3,6,12,24,43,68,159,318,631,1244,2444,4638,8350,13306,31249,
%T 62498,124991,249964,499884,999518,1998110,3992826,7976984,15904776,
%U 31622086,62494618,121995928,232079906,417569970,665554652,1563189209,3126378418,6252756831,12505513644
%N a(n) = a(1) + a(2) + ... + a(n-1) - a(m) for n >= 4, where m = 2*n - 3 - 2^(p+1) and p is the unique integer such that 2^p < n - 1 <= 2^(p+1), starting with a(1) = 1, a(2) = 2, and a(3) = 1.
%H Michael De Vlieger, <a href="/A049900/b049900.txt">Table of n, a(n) for n = 1..3327</a>
%p s := proc(n) option remember; `if`(n < 1, 0, a(n) + s(n - 1)) end proc:
%p a := proc(n) option remember;
%p `if`(n < 4, [1, 2, 1][n], s(n - 1) - a(-2^ceil(log[2](n - 1)) + 2*n - 3)):
%p end proc:
%p seq(a(n), n = 1..40); # _Petros Hadjicostas_, Nov 15 2019
%t Nest[Append[#1, Total@ #1 - #1[[2 #2 - 3 - 2^Ceiling@ Log2[#2 - 1]]]] & @@ {#, Length@ # + 1} &, {1, 2, 1}, 34] (* _Michael De Vlieger_, Nov 19 2019 *)
%o (PARI) lista(nn) = {my(va = vector(nn), s); va[1] = 1; va[2] = 2; va[3] = 1; s = sum(k=1, 3, va[k]); for (n=4, nn, va[n] = s - va[2*n - 3 - 2^ceil(log(n-1)/log(2))]; s += va[n];); va;} \\ _Michel Marcus_, Nov 20 2019
%K nonn
%O 1,2
%A _Clark Kimberling_
%E Name edited by and more terms from _Petros Hadjicostas_, Nov 15 2019