OFFSET
0,3
COMMENTS
a(0) could be considered to be 0 if the binary representation of zero were chosen to be the empty string. - Jason Kimberley, Sep 19 2011
From Bernard Schott, Jun 15 2021: (Start)
Except for a(0) = 1, every term is even.
For each q >= 0, there is one and only one odd number h such that a(n) = 2*q iff n = h*2^m-1 for m >= 1 when q = 0, and for m >= 0 when q >= 1 (see A345401 and some examples below).
a(n) = 0 iff n = 2^m-1 for m >= 1 (Mersenne numbers) (A000225).
a(n) = 2 iff n = 3*2^m-1 for m >= 0 (A153893).
a(n) = 4 iff n = 7*2^m-1 for m >= 0 (A086224).
a(n) = 6 iff n = 5*2^m-1 for m >= 0 (A153894).
a(n) = 8 iff n = 15*2^m-1 for m >= 0 (A196305).
a(n) = 10 iff n = 11*2^m-1 for m >= 0 (A086225).
a(n) = 12 iff n = 13*2^m-1 for m >= 0 (A198274).
For k >= 1, a(n) = 2^k iff n = (2^(k+1)-1)*2^m - 1 for m >= 0.
Explanation for a(n) = 2:
For m >= 0, A153893(m) = 3*2^m-1 -> 1011...11 -> 0100...00 -> 10 -> 2 where 1011...11_2 is 10 followed by m 1's. (End)
LINKS
Indranil Ghosh, Table of n, a(n) for n = 0..10000 (first 1024 terms from T. D. Noe)
FORMULA
a(2n) = 2*A059894(n), a(2n+1) = a(2n) - 2^floor(log_2(n)+1). - Ralf Stephan, Aug 21 2003
EXAMPLE
4 -> 100 -> 011 -> 110 -> 6.
MAPLE
A036044 := proc(n)
local bcr ;
if n = 0 then
return 1;
end if;
convert(n, base, 2) ;
bcr := [seq(1-i, i=%)] ;
add(op(-k, bcr)*2^(k-1), k=1..nops(bcr)) ;
end proc:
seq(A036044(n), n=0..200) ; # R. J. Mathar, Nov 06 2017
MATHEMATICA
dtn[ L_ ] := Fold[ 2#1+#2&, 0, L ]; f[ n_ ] := dtn[ Reverse[ 1-IntegerDigits[ n, 2 ] ] ]; Table[ f[ n ], {n, 0, 100} ]
Table[FromDigits[Reverse[IntegerDigits[n, 2]/.{1->0, 0->1}], 2], {n, 0, 80}] (* Harvey P. Dale, Mar 08 2015 *)
PROG
(Haskell)
import Data.List (unfoldr)
a036044 0 = 1
a036044 n = foldl (\v d -> 2 * v + d) 0 (unfoldr bc n) where
bc 0 = Nothing
bc x = Just (1 - m, x') where (x', m) = divMod x 2
-- Reinhard Zumkeller, Sep 16 2011
(Magma) A036044:=func<n|n eq 0 select 1 else SequenceToInteger(Reverse([1-b:b in IntegerToSequence(n, 2)]), 2)>; // Jason Kimberley, Sep 19 2011
(PARI) a(n)=fromdigits(Vecrev(apply(n->1-n, binary(n))), 2) \\ Charles R Greathouse IV, Apr 22 2015
(Python)
def comp(s): z, o = ord('0'), ord('1'); return s.translate({z:o, o:z})
def BCR(n): return int(comp(bin(n)[2:])[::-1], 2)
print([BCR(n) for n in range(75)]) # Michael S. Branicky, Jun 14 2021
(Python)
def A036044(n): return -int((s:=bin(n)[-1:1:-1]), 2)-1+2**len(s) # Chai Wah Wu, Feb 04 2022
CROSSREFS
KEYWORD
AUTHOR
STATUS
approved