cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

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.

Original entry on oeis.org

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

Views

Author

Rémy Sigrist, Apr 25 2021

Keywords

Comments

In other words, this sequence gives the last run of 1's in the binary expansion of a number.

Examples

			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
		

Crossrefs

Programs

  • Mathematica
    Array[FromDigits[If[Length[s=Split@IntegerDigits[#,2]]>1,Flatten[s[[-2;;]]],First@s],2]&,100,0] (* Giorgos Kalogeropoulos, Apr 27 2021 *)
  • 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

Formula

a(2*n) = 2*a(n).
a(a(n)) = a(n).
a(n) <= n with equality iff n belongs to A023758.