login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A285097 a(n) = difference between the positions of two least significant 1-bits in base-2 representation of n, or 0 if there are less than two 1-bits in n (when n is either zero or a power of 2). 3

%I #21 Nov 21 2023 18:16:04

%S 0,0,0,1,0,2,1,1,0,3,2,1,1,2,1,1,0,4,3,1,2,2,1,1,1,3,2,1,1,2,1,1,0,5,

%T 4,1,3,2,1,1,2,3,2,1,1,2,1,1,1,4,3,1,2,2,1,1,1,3,2,1,1,2,1,1,0,6,5,1,

%U 4,2,1,1,3,3,2,1,1,2,1,1,2,4,3,1,2,2,1,1,1,3,2,1,1,2,1,1,1,5,4,1,3,2,1,1,2,3,2,1,1,2,1,1,1,4,3,1,2,2,1,1,1

%N a(n) = difference between the positions of two least significant 1-bits in base-2 representation of n, or 0 if there are less than two 1-bits in n (when n is either zero or a power of 2).

%C a(1+n) is the length of the least significant run of 0-bits in n, or 0 if n is one of terms of A000225. - _Antti Karttunen_, Oct 14 2023

%H Antti Karttunen, <a href="/A285097/b285097.txt">Table of n, a(n) for n = 0..8192</a>

%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>

%F If A000120(n) < 2, a(n) = 0, otherwise a(n) = A285099(n) - A007814(n) = A007814(A129760(n)) - A007814(n).

%F a(n) = 0 if n is 0 or of the form 2^k, (k>=0), otherwise a(n) = v_2(A000265(n)-1), where v_2(i) = A007814(i). - _Ridouane Oudra_, Oct 20 2019

%e For n = 3, "11" in binary, the second least significant 1-bit (the second 1-bit from the right) is at position 1 and the rightmost 1-bit is at position 0), thus a(3) = 1-0 = 1.

%e For n = 4, "100" in binary, there is just one 1-bit present, thus a(4) = 0.

%e For n = 5, "101" in binary, the second 1-bit from the right is at position 2, and the least significant 1 is at position 0, thus a(5) = 2-0 = 2.

%e For n = 26, "11010" in binary, the second 1-bit from the right is at position 3, and the least significant 1 is at position 1, thus a(26) = 3-1 = 2.

%t a007814[n_]:=IntegerExponent[n, 2]; a285099[n_]:=If[DigitCount[n, 2, 1]<2, 0, a007814[BitAnd[n, n - 1]]]; a[n_]:=If[DigitCount[n, 2, 1]<2, 0,a285099[n] - a007814[n]]; Table[a[n], {n, 0, 150}] (* _Indranil Ghosh_, Apr 20 2017 *)

%o (Scheme) (define (A285097 n) (if (<= (A000120 n) 1) 0 (- (A285099 n) (A007814 n))))

%o (Python)

%o import math

%o def a007814(n): return int(math.log(n - (n & n - 1), 2))

%o def a285099(n): return 0 if bin(n)[2:].count("1") < 2 else a007814(n & (n - 1))

%o def a(n): return 0 if bin(n)[2:].count("1")<2 else a285099(n) - a007814(n) # _Indranil Ghosh_, Apr 20 2017

%o (PARI) A285097(n) = if(!n || !bitand(n,n-1), 0, valuation((n>>valuation(n,2))-1, 2)); \\ _Antti Karttunen_, Oct 14 2023

%Y Cf. A000120, A000225, A000265, A007814, A119387, A129760, A285099, A366370.

%K nonn,base

%O 0,6

%A _Antti Karttunen_, Apr 20 2017

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 24 04:14 EDT 2024. Contains 371918 sequences. (Running on oeis4.)