OFFSET
1,2
LINKS
David A. Corneth, Table of n, a(n) for n = 1..1000
EXAMPLE
a(5) = a(1) + a(2) + a(3) + a(4) + a(m) = 1 + 3 + 2 + 9 + a(m) = 15 + a(m). where m = 2*n - 2 - 2^(p+1) and 2^p < n - 1 = 4 <= 2^(p+1). We have p = 1 giving m = 2*5 - 2 - 4 = 4. As a(m) = a(4) = 9, we have a(5) = 15 + 9 = 24. - David A. Corneth, Apr 26 2020
MAPLE
s := proc(n) option remember; `if`(n < 1, 0, a(n) + s(n - 1)) end proc:
a := proc(n) option remember;
`if`(n < 4, [1, 3, 2][n], s(n - 1) + a(-2^ceil(log[2](n - 1)) + 2*n - 2)):
end proc:
seq(a(n), n = 1..40); # Petros Hadjicostas, Apr 25 2020
# Alternative, uses A062050:
a := proc(n) option remember; if n < 4 then [1, 3, 2][n] else
add(a(i), i = 1..n-1 ) + a(2*A062050(n-2)) fi end:
seq(a(n), n = 1..35); # Peter Luschny, Aug 06 2021
MATHEMATICA
a[1] = 1; a[2] = 3; a[3] = 2; a[n_] := a[n] = Sum[a[k], {k, 1, n - 1}] + a[2*n - 2 - 2^Floor[1 + Log[2, n - 2]]]; Table[a[n], {n, 1, 30}] (* Vaclav Kotesovec, Apr 26 2020 *)
PROG
(PARI) lista(nn) = { my(va = vector(nn)); va[1] = 1; va[2] = 3; va[3] = 2; my(sa = vecsum(va)); for (n=4, nn, va[n] = sa + va[2*n - 2 - 2*2^logint(n-2, 2)]; sa += va[n]; ); va; } \\ Michel Marcus, Apr 26 2020 (with nn > 2)
(PARI) first(n) = {n = max(n, 3); my(res = vector(n), s = 6, p = 1); res[1] = 1; res[2] = 3; res[3] = 2; for(i = 4, n, if(i - 1 > 1 << (p + 1), p++); res[i] = s + res[2*i-2-2^(p+1)]; s += res[i]) ; res} \\ David A. Corneth, Apr 26 2020
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
EXTENSIONS
Name edited by Petros Hadjicostas, Apr 25 2020
More terms from David A. Corneth, Apr 26 2020
STATUS
approved