login
A049903
a(n) = a(1) + a(2) + ... + a(n-1) - a(m) for n >= 4, where m = 2*n - 2 - 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.
0
1, 2, 1, 2, 4, 8, 16, 26, 34, 92, 184, 362, 706, 1346, 2422, 3860, 5206, 14270, 28540, 57074, 114130, 228194, 456118, 911252, 1819990, 3629570, 7216336, 14261552, 27840046, 52961774, 95291566, 151882910, 204844684, 561572276
OFFSET
1,2
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, 2, 1][n], s(n - 1) - a(-2^ceil(log[2](n - 1)) + 2*n - 2)):
end proc:
seq(a(n), n = 1..40); # Petros Hadjicostas, Nov 20 2019
PROG
(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 - 2 - 2^ceil(log(n-1)/log(2))]; s += va[n]; ); va; } \\ Petros Hadjicostas, Nov 20 2019 by modifying a program of Michel Marcus
CROSSREFS
Sequence in context: A016013 A193384 A325844 * A325665 A325843 A024739
KEYWORD
nonn
EXTENSIONS
Name edited by Petros Hadjicostas, Nov 20 2019
STATUS
approved