%I #18 Feb 28 2019 11:22:22
%S 0,1,2,2,4,3,6,3,8,5,10,4,12,7,14,4,16,9,18,6,20,11,22,5,24,13,26,8,
%T 28,15,30,5,32,17,34,10,36,19,38,7,40,21,42,12,44,23,46,6,48,25,50,14,
%U 52,27,54,9,56,29,58,16,60,31,62,6,64,33,66,18,68,35,70,11,72
%N a(1) = 0; thereafter a(2*n) = a(n) + 1, a(2*n+1) = 2*n.
%C In the binary representation of n, swallow all zeros from the right, then add the number of swallowed zeros, and subtract 1. - _Ralf Stephan_, Aug 22 2013
%H T. D. Noe, <a href="/A089265/b089265.txt">Table of n, a(n) for n=1..1000</a>
%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>
%F a(1) = 0; thereafter a(2*n) = a(n) + 1, a(2*n+1) = 2*n.
%F a(n) = A007814(n) + 2*A025480(n-1) = A007814(n) + A000265(n) - 1.
%F G.f.: sum(k>=0, (t^2+2t^3-t^4)/(1-t^2)^2, t=(x^2)^k).
%F a((2*n-1)*2^p) = p + 2*(n-1), p >= 0. - _Johannes W. Meijer_, Jan 23 2013
%p nmax:=73: for p from 0 to ceil(simplify(log[2](nmax))) do for n from 1 to ceil(nmax/(p+2)) do a((2*n-1)*2^p) := p + 2*(n-1) od: od: seq(a(n), n=1..nmax); # _Johannes W. Meijer_, Jan 23 2013
%t a[n_] := With[{v = IntegerExponent[n, 2]}, v + n/2^v - 1];
%t Array[a, 100] (* _Jean-François Alcover_, Feb 28 2019 *)
%o (PARI) a(n) = valuation(n,2) + n/2^valuation(n,2) - 1
%Y First differences of A005766.
%Y Cf. A003602, A220466.
%K nonn,easy
%O 1,3
%A _Ralf Stephan_, Oct 30 2003