The OEIS mourns the passing of Jim Simons and is grateful to the Simons Foundation for its support of research in many branches of science, including the OEIS.
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!)
A342241 a(n) is the least k > 0 such that the first k bits and the last k bits in the binary expansion of n are the same. 2
1, 1, 2, 1, 3, 1, 3, 1, 4, 1, 2, 1, 4, 1, 4, 1, 5, 1, 2, 1, 5, 1, 2, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 2, 1, 3, 1, 2, 1, 6, 1, 2, 1, 6, 1, 2, 1, 6, 1, 6, 1, 6, 1, 3, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 2, 1, 3, 1, 2, 1, 7, 1, 2, 1, 3, 1, 2, 1, 7, 1, 2, 1, 7, 1, 2 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,3
COMMENTS
This sequence gives the length of the least nonempty prefix that is also a suffix of the binary expansion of a number.
LINKS
FORMULA
a(n) = 1 iff n = 0 or n is odd.
a(n) <= A070939(n) with equality iff n belongs to A091065.
a(n) = A070939(A342242(n)).
EXAMPLE
For n = 42:
- the binary representation of 42 is "101010",
- the first bit ("1") and the last bit ("0") do not match,
- the first 2 bits ("10") and the last 2 bits ("10") match,
- so a(42) = 2.
PROG
(PARI) a(n) = { my (b=if (n, binary(n), [0])); for (w=1, oo, if (b[1..w]==b[#b+1-w..#b], return (w))) }
(Python)
def a(n):
b = bin(n)[2:]
for i in range(1, len(b)+1):
if b[:i] == b[-i:]: return i
print([a(n) for n in range(87)]) # Michael S. Branicky, Mar 07 2021
CROSSREFS
Sequence in context: A073407 A049994 A135732 * A322584 A356224 A364767
KEYWORD
nonn,base,easy
AUTHOR
Rémy Sigrist, Mar 07 2021
STATUS
approved

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 May 17 19:53 EDT 2024. Contains 372607 sequences. (Running on oeis4.)