OFFSET
0,3
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
N. J. A. Sloane and J. A. Sellers, On non-squashing partitions, Discrete Math., 294 (2005), 259-274.
FORMULA
MAPLE
S := 2; f := proc(n) global S; option remember; if n=0 then RETURN(0); fi; if n mod 2 = 0 then RETURN(S*f(n/2)); else f((n-1)/2)+1; fi; end;
MATHEMATICA
a[0]=0; a[n_] := a[n] = If[EvenQ[n], 2*a[n/2], a[(n-1)/2]+1]; Array[a, 76, 0] (* Jean-François Alcover, Aug 12 2017 *)
PROG
(PARI) a(n)=if(n<1, 0, if(n%2==0, 2*a(n/2), a((n-1)/2)+1))
(Haskell)
import Data.List (transpose)
a087808 n = a087808_list !! n
a087808_list = 0 : concat
(transpose [map (+ 1) a087808_list, map (* 2) $ tail a087808_list])
-- Reinhard Zumkeller, Mar 18 2015
(Scheme) (define (A087808 n) (cond ((zero? n) n) ((even? n) (* 2 (A087808 (/ n 2)))) (else (+ 1 (A087808 (/ (- n 1) 2)))))) ;; Antti Karttunen, Oct 07 2016
(Python)
from functools import lru_cache
@lru_cache(maxsize=None)
def A087808(n): return 0 if n == 0 else A087808(n//2) + (1 if n % 2 else A087808(n//2)) # Chai Wah Wu, Mar 08 2022
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Ralf Stephan, Oct 14 2003
STATUS
approved