OFFSET
0,3
COMMENTS
LINKS
FORMULA
a(n) = n if n is even, a((n-1)/2) if odd.
a(n)/2 = A025480(n).
a(n) = A000265(n+1) - 1. - M. F. Hasler, Mar 16 2018
a(n) = n - A331739(n+1). - Federico Provvedi, Dec 21 2021
MAPLE
f:= n -> (n+1)/2^padic:-ordp(n+1, 2)-1:
map(f, [$0..100]); # Robert Israel, Mar 18 2018
MATHEMATICA
Table[If[EvenQ[n], n, FromDigits[Flatten[Most[Split[IntegerDigits[n, 2]]]], 2]], {n, 0, 100}] (* Harvey P. Dale, Feb 15 2014 *)
a[n_] := BitShiftRight[n + 1, IntegerExponent[n+1, 2]] - 1; a[Range[0, 100]] (* Federico Provvedi, Dec 21 2021 *)
PROG
(Haskell)
a153733 n = if b == 0 then n else a153733 n' where (n', b) = divMod n 2
-- Reinhard Zumkeller, Jul 22 2014
From M. F. Hasler, Mar 16 2018: (Start)
(PARI) A153733(n)=(n+=1)>>valuation(n, 2)-1 \\ most efficient variant: use this.
(PARI) {a(n)=while(bittest(n, 0), n>>=1); n} \\ for illustration: as long as there's a trailing bit 1, remove it.
(PARI) a(n)=for(i=0, n, bittest(n, i)||return(n>>i)) \\ scan the trailing 1's, then remove all of them at once. (End)
(Python)
def a(n):
while n&1: n >>= 1
return n
print([a(n) for n in range(100)]) # Michael S. Branicky, Dec 18 2021
(Python)
def A153733(n): return n>>(~(n+1)&n).bit_length() # Chai Wah Wu, Jul 08 2022
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Reinhard Zumkeller, Dec 31 2008
STATUS
approved