login
A342410
The binary expansion of a(n) corresponds to that of n where all the 1's have been replaced by 0's except in the last run of 1's.
5
0, 1, 2, 3, 4, 1, 6, 7, 8, 1, 2, 3, 12, 1, 14, 15, 16, 1, 2, 3, 4, 1, 6, 7, 24, 1, 2, 3, 28, 1, 30, 31, 32, 1, 2, 3, 4, 1, 6, 7, 8, 1, 2, 3, 12, 1, 14, 15, 48, 1, 2, 3, 4, 1, 6, 7, 56, 1, 2, 3, 60, 1, 62, 63, 64, 1, 2, 3, 4, 1, 6, 7, 8, 1, 2, 3, 12, 1, 14, 15
OFFSET
0,3
COMMENTS
In other words, this sequence gives the last run of 1's in the binary expansion of a number.
FORMULA
a(2*n) = 2*a(n).
a(a(n)) = a(n).
a(n) <= n with equality iff n belongs to A023758.
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