OFFSET
1,2
LINKS
Reinhard Zumkeller, Rows n=1..13 of triangle, flattened
Ralf Stephan, Some divide-and-conquer sequences ...
Ralf Stephan, Table of generating functions
FORMULA
a(n) = 2n - 1 - floor(log_2(n)).
a(2^n-1) = 2^(n+1) - (n+2) = A000295(n+1), the Eulerian numbers.
a(0)=0, a(2n) = a(n) + 2n - 1, a(2n+1) = a(n) + 2n + 1. - Ralf Stephan, Oct 11 2003
MAPLE
Digits := 100: [seq(2*n-1-floor(evalf(log(n)/log(2))), n=1..100)];
MATHEMATICA
a[0] = 0; a[n_?EvenQ] := a[n] = a[n/2]+n-1; a[n_?OddQ] := a[n] = a[(n-1)/2]+n; Table[a[n], {n, 1, 100}] (* Jean-François Alcover, Dec 27 2011, after Ralf Stephan *)
PROG
(Haskell)
a049039 n k = a049039_tabl !! (n-1) !! (k-1)
a049039_row n = a049039_tabl !! (n-1)
a049039_tabl = f 1 1 [1..] where
f k p xs = ys : f (2 * k) (1 - p) (dropWhile (<= last ys) xs) where
ys = take k $ filter ((== p) . (`mod` 2)) xs
-- Reinhard Zumkeller, Jan 18 2012, Jul 08 2011
(PARI) a(n) = n<<1 - 1 - logint(n, 2); \\ Kevin Ryde, Feb 12 2022
(Python)
def A049039(n): return (n<<1)-n.bit_length() # Chai Wah Wu, Aug 01 2022
CROSSREFS
KEYWORD
easy,nonn,nice,tabf
AUTHOR
EXTENSIONS
Keyword tabf added by Reinhard Zumkeller, Jan 22 2012
STATUS
approved