A070940 Number of digits that must be counted from left to right to reach the last 1 in the binary representation of n.
1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 4, 2, 4, 3, 4, 1, 5, 4, 5, 3, 5, 4, 5, 2, 5, 4, 5, 3, 5, 4, 5, 1, 6, 5, 6, 4, 6, 5, 6, 3, 6, 5, 6, 4, 6, 5, 6, 2, 6, 5, 6, 4, 6, 5, 6, 3, 6, 5, 6, 4, 6, 5, 6, 1, 7, 6, 7, 5, 7, 6, 7, 4, 7, 6, 7, 5, 7, 6, 7, 3, 7, 6, 7, 5, 7, 6, 7, 4, 7, 6, 7, 5, 7
Offset: 1
Examples
a(10)=3 is the number of digits that must be counted from left to right to reach the last 1 in 1010, the binary representation of 10. The table starts: 1 1 2 1 3 2 3 1 4 3 4 2 4 3 4
Links
Crossrefs
Programs
-
Haskell
a070940 = maximum . a080080_row -- Reinhard Zumkeller, Apr 22 2013
-
Maple
A070940 := n -> if n mod 2 = 0 then A070939(n)-A001511(n/2) else A070939(n); fi;
-
Mathematica
Table[Length[Union[Table[GCD[2^n, Binomial[n, j]], {j, 0, n}]]], {n, 0, 256}] f[n_] := Position[ IntegerDigits[n, 2], 1][[ -1, 1]]; Table[ f[n], {n, 105}] (* Robert G. Wilson v, Dec 01 2004 *) (* By exploiting the "positional" regularity of the sequence *) b = {}; a = {1, 1}; Do[a = Riffle[a, j]; b = AppendTo[b, a[[1 ;; Floor[Length[a]/2]]]] // Flatten, {j, 1, 10}]; Print[b[[1 ;; 100]]] (* Andres Cicuttin, May 18 2017 *) (* By following the alternative definition "Number of binary digits of the largest integer odd factor of n" *) c = Table[IntegerDigits[n/(2^IntegerExponent[n, 2]), 2] // Length , {n, 2^10 - 1}]; Print[c[[1 ;; 100]]] (* Andres Cicuttin, May 18 2017 *) lidn[n_]:=Module[{idn=IntegerDigits[n,2]},idn=If[Last[idn]==0,Flatten[ Most[ Split[ idn]]],idn];Length[idn]]; Array[lidn,100] (* Harvey P. Dale, Oct 18 2020 *) Table[IntegerLength[FromDigits[Reverse[IntegerDigits[n,2]]]],{n,100}] (* Harvey P. Dale, Jan 26 2025 *)
-
Python
def A070940(n): while n%2 == 0: n = n//2 a = 0 while n != 0: n, a = n//2, a+1 return a n = 0 while n < 100: n = n+1 print(n,A070940(n)) # A.H.M. Smeets, Aug 19 2019
-
Python
def A070940(n): return n.bit_length()-(~n&n-1).bit_length() # Chai Wah Wu, Jul 13 2022
-
R
blocklevel <- 7 # by choice a <- 1 for(m in 0:blocklevel) for(k in 0:(2^m-1)){ a[2^(m+1)+2*k ] <- a[2^m+k] a[2^(m+1)+2*k+1] <- m + 2 } a # Yosu Yurramendi, Aug 08 2019
Formula
a(n) = f(n, 1), f(n, k) = if n=1 then k else f(floor(n/2), k+(if k>1 then 1 else n mod 2)). - Reinhard Zumkeller, Feb 01 2003
G.f.: Sum_{k>=0} (t/(1-t^2)) * (1 + Sum_{L>=1} t^2^L), where t=x^2^k. - Ralf Stephan, Mar 15 2004
a(1) = 1 and for m >= 0, 0 <= k < 2^m, a(2^(m+1)+2*k) = a(2^m+k), a(2^(m+1)+2*k+1) = m+2. - Yosu Yurramendi, Aug 08 2019
Extensions
Entry revised by Ralf Stephan, Nov 29 2004
Comments