OFFSET
0,3
COMMENTS
To make this a permutation of nonnegative integers, we subtract one from each run count except for the most significant run, e.g. a(11) = 9, as 11 = 1011 and 9+1 = 10 = 5^1 * 3^(1-1) * 2^(2-1).
LINKS
Paul Tek (terms 0..10000) & Antti Karttunen, Table of n, a(n) for n = 0..16384
FORMULA
PROG
(Haskell)
import Data.List (group)
a075157 0 = 0
a075157 n = product (zipWith (^) a000040_list rs') - 1 where
rs' = reverse $ r : map (subtract 1) rs
(r:rs) = reverse $ map length $ group $ a030308_row n
-- Reinhard Zumkeller, Aug 04 2014
(PARI)
A005811(n) = hammingweight(bitxor(n, n>>1)); \\ This function from Gheorghe Coserea, Sep 03 2015
A286468(n) = { my(p=((n+1)%2), i=0, m=1); while(n>0, if(((n%2)==p), m *= prime(i), p = (n%2); i = i+1); n = n\2); m };
(Scheme)
(define (A075157 n) (if (zero? n) n (+ -1 (* (A000040 (A005811 n)) (fold-left (lambda (a r) (* (A003961 a) (A000079 (- r 1)))) 1 (binexp->runcount1list n))))))
(define (binexp->runcount1list n) (if (zero? n) (list) (let loop ((n n) (rc (list)) (count 0) (prev-bit (modulo n 2))) (if (zero? n) (cons count rc) (if (eq? (modulo n 2) prev-bit) (loop (floor->exact (/ n 2)) rc (1+ count) (modulo n 2)) (loop (floor->exact (/ n 2)) (cons count rc) 1 (modulo n 2)))))))
;; Or, using the code of A286468:
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Sep 13 2002
EXTENSIONS
Entry revised, PARI-program added and the old incorrect Scheme-program replaced with a new one by Antti Karttunen, May 17 2017
STATUS
approved