OFFSET
0,3
COMMENTS
All terms belong to A091065.
LINKS
FORMULA
EXAMPLE
For n = 814:
- the binary expansion of 814 is "1100101110",
- "1" does not match "0",
- "11" does not match "10",
- "110" matches "110",
- so the binary representation of a(814) is "110",
- and a(814) = 6.
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 (fromdigits(b[1..w], 2)))) }
(Python)
def a(n):
b = bin(n)[2:]
for i in range(1, len(b)+1):
if b[:i] == b[-i:]: return int(b[:i], 2)
print([a(n) for n in range(80)]) # Michael S. Branicky, Mar 07 2021
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
Rémy Sigrist, Mar 07 2021
STATUS
approved