login
A142721
An even-odd sequence: a(n) = n/2 if n is even, or a(n-1) + 2^floor(log_2(n+1)) otherwise.
0
0, 2, 1, 5, 2, 6, 3, 11, 4, 12, 5, 13, 6, 14, 7, 23, 8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 47, 16, 48, 17, 49, 18, 50, 19, 51, 20, 52, 21, 53, 22, 54, 23, 55, 24, 56, 25, 57, 26, 58, 27, 59, 28, 60, 29, 61, 30, 62, 31, 95, 32, 96, 33, 97, 34, 98, 35, 99, 36, 100
OFFSET
0,2
MATHEMATICA
a[0] = 0; a[n_] := a[n] = If[Mod[n, 2] == 0, n/2, a[n - 1] + 2^(Floor[Log[2, 1 + n]])]; Table[a[n], {n, 0, 100}]
nxt[{n_, a_}]:={n+1, If[EvenQ[n+1], (n+1)/2, a+2^Floor[Log[2, n+2]]]}; Transpose[ NestList[ nxt, {0, 0}, 100]][[2]] (* Harvey P. Dale, Feb 26 2013 *)
PROG
(PARI) a(n)=n\2+if(n%2, 2^(log(n+1.5)\log(2))) \\ Charles R Greathouse IV, Jan 30 2012
CROSSREFS
Sequence in context: A253809 A262213 A178913 * A316891 A152992 A185727
KEYWORD
nonn,less,easy
AUTHOR
STATUS
approved