OFFSET
0,3
COMMENTS
In other words, this sequence gives the last run of 1's in the binary expansion of a number.
LINKS
FORMULA
EXAMPLE
The first terms, alongside their binary expansion, are:
n a(n) bin(n) bin(a(n))
-- ---- ------ ---------
0 0 0 0
1 1 1 1
2 2 10 10
3 3 11 11
4 4 100 100
5 1 101 1
6 6 110 110
7 7 111 111
8 8 1000 1000
9 1 1001 1
10 2 1010 10
11 3 1011 11
12 12 1100 1100
13 1 1101 1
14 14 1110 1110
15 15 1111 1111
MATHEMATICA
Array[FromDigits[If[Length[s=Split@IntegerDigits[#, 2]]>1, Flatten[s[[-2;; ]]], First@s], 2]&, 100, 0] (* Giorgos Kalogeropoulos, Apr 27 2021 *)
PROG
(PARI) a(n) = { if (n, my (z=valuation(n, 2), o=valuation(n/2^z+1, 2)); (2^o-1)*2^z, 0) }
(Python)
def A342410(n):
if n == 0 : return 0
for i, d in enumerate(bin(n)[2:].split('0')[::-1]):
if d != '': return int(d+'0'*i, 2) # Chai Wah Wu, Apr 29 2021
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
Rémy Sigrist, Apr 25 2021
STATUS
approved