login
A342126
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 first run of 1's.
6
0, 1, 2, 3, 4, 4, 6, 7, 8, 8, 8, 8, 12, 12, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 24, 24, 24, 24, 28, 28, 30, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 48, 48, 48, 48, 48, 48, 48, 48, 56, 56, 56, 56, 60, 60, 62, 63, 64, 64, 64, 64
OFFSET
0,3
COMMENTS
In other words, this sequence gives the first run of 1's in the binary expansion of a number.
A023758(n) appears A057728(n) times.
FORMULA
a(n) = n - A087734(n).
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 4 101 100
6 6 110 110
7 7 111 111
8 8 1000 1000
9 8 1001 1000
10 8 1010 1000
11 8 1011 1000
12 12 1100 1100
13 12 1101 1100
14 14 1110 1110
15 15 1111 1111
PROG
(PARI) a(n) = { my (b=binary(n), p=1); for (k=1, #b, b[k] = p*=b[k]); fromdigits(b, 2) }
(Python)
def A342126(n):
s = bin(n)[2:]
i = s.find('0')
return n if i == -1 else (2**i-1)*2**(len(s)-i) # Chai Wah Wu, Apr 29 2021
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
Rémy Sigrist, Apr 25 2021
STATUS
approved