OFFSET
0,3
COMMENTS
The sequence is well-defined, see Problem 5 of IMO 2019.
From Natalia L. Skirrow, May 24 2026: (Start)
The maximum a(n) for n in the range [0..2^l) is binomial(l+1,2), achieved by n = 2^l-2^floor(l/2) = A122746(l-1).
Sum_{n=0..2^l-1} a(n) = 2^(l-2)*l*(l+1) = A001788(l).
Sum_{n=0..2^l-1} a(n)^2 = 2^(l-4)*l*(l+1)*(l+2)*(l+1/3).
Thus, the waiting time for an n uniformly sampled in [0..2^l) has expectation l*(l+1)/4 and variance l*(l+1)*(l+1/2)/12.
If n is written as the binary word 1^(o_0) 0^(z_0) 1^(o_1) ..., then (with O_i = Sum_{j=0..i} o_j), a(n) = Sum_i 2*O_i*z_i + o_i. (End)
LINKS
Rémy Sigrist, Table of n, a(n) for n = 0..8192
International Mathematical Olympiad, Problem 5 of IMO 2019.
FORMULA
a(2*n) = a(n) + 2*A000120(n), a(2*n+1) = a(n)+1. - Natalia L. Skirrow, May 24 2026
EXAMPLE
326730_10 = 1001111110001001010_2, whose run-length sequences are o = 1,6,1,1,1 and z = 2,3,2,1,1 with O = 1,7,8,9,10, so a(326730) = Sum_i 2*O_i*z_i+o_i = 2*1*2+1 + 2*7*3+6 + 2*8*2+1 + 2*9*1+1 + 2*10*1+1 = 126. - Natalia L. Skirrow, May 24 2026
PROG
(PARI) A326730(n) = my(b=Vecrev(binary(n)), m=vecsum(b)); 2*sum(i=1, #b, i*b[i]) - m^2;
(Python)
(Python)
def a(n): return 2*sum(i for i, bi in enumerate(bin(n)[2:][::-1], 1) if bi == "1") - n.bit_count()**2 # Michael S. Branicky, May 24 2026
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Max Alekseyev, Jul 22 2019
STATUS
approved
