OFFSET
0,4
COMMENTS
Iterating a(n), a(a(n)), ... eventually leads to 2^A000120(n) - 1. - Franklin T. Adams-Watters, Apr 09 2010
LINKS
Indranil Ghosh, Table of n, a(n) for n = 0..20000 (first 1024 terms from T. D. Noe)
FORMULA
a(n) = A053645(n) * A000035(n) + A004526(n) = most significant bit(n) * least significant bit(n) + floor(n/2).
a(0)=0, a(1)=1, a(2n) = n, a(2n+1) = 2a(n) + 2a(n+1) - n. - Ralf Stephan, Oct 24 2003
EXAMPLE
For n = 35, 35_10 = 100011_2, which after rotating one binary place to the right becomes 110001. Now, 110001_2 = 49_10. So, a(35) = 49. - Indranil Ghosh, Jan 21 2017
MAPLE
A038572 := proc(n)
convert(n, base, 2) ;
ListTools[Rotate](%, 1) ;
add( op(i, %)*2^(i-1), i=1..nops(%)) ;
end proc: # R. J. Mathar, May 20 2016
MATHEMATICA
Table[ FromDigits[ RotateRight[ IntegerDigits[n, 2]], 2], {n, 0, 80}] (* Robert G. Wilson v *)
PROG
(Haskell)
a038572 0 = 0
a038572 n = a053645 n * m + n' where (n', m) = divMod n 2
-- Reinhard Zumkeller, Dec 03 2012
(PARI) a(n)=if(n<2, return(n)); my(d=binary(n)); fromdigits(concat(d[#d], d[1..#d-1]), 2) \\ Charles R Greathouse IV, Sep 02 2015
(Python)
def A038572(n):
x = bin(n)[2:]
return int(x[-1]+x[:-1], 2) # Indranil Ghosh, Jan 21 2017
(Python)
def A038572(n): return (n>>1)+(1<<n.bit_length()-1 if n&1 else 0) # Chai Wah Wu, Jan 22 2023
CROSSREFS
KEYWORD
easy,base,nonn,nice
AUTHOR
STATUS
approved