A387269 Numbers whose binary expansion consists of alternating runs of 1's and 0's where each run of 0's is exactly one longer than the preceding run of 1's, and the expansion ends with a 0-run.
4, 24, 36, 112, 152, 196, 292, 480, 624, 792, 900, 1176, 1220, 1572, 1984, 2340, 2528, 3184, 3608, 3844, 4720, 4888, 4996, 6296, 6340, 7204, 8064, 9368, 9412, 9764, 10176, 12580, 12768, 14448, 15384, 15876, 18724, 18912, 19568, 19992, 20228, 25200, 25368, 25476
Offset: 1
Examples
36 = 100100_2 is a term since its pairs of (1 then 0) runs are (1,2), (1,2).
Links
- Ahmet Caglar Saygili, Table of n, a(n) for n = 1..10000
- Sean A. Irvine, Java program (github)
Programs
-
Julia
function ok(n::Integer)::Bool n > 0 && iseven(n) || return false x = unsigned(n) while x != 0 z = trailing_zeros(x); x >>= z o = trailing_ones(x) z == o + 1 || return false x >>= o end true end [k for k in 0:10^5 if ok(k)]
-
PARI
isok(k) = if (!(k%2), my(b=binary(k), pos=1, d, dd); for (i=1, #b-1, if (b[i] != b[i+1], if (b[i], d = i-pos+1; pos = i+1, dd = i-pos+1; pos = i+1; if (dd != d+1, return(0))))); dd = #b - pos+1; if (dd != d+1, return(0)); return(1);); \\ Michel Marcus, Aug 26 2025
-
Python
from itertools import groupby def ok(n): L = [len(list(g)) for k, g in groupby(bin(n)[2:])] return (m:=len(L))&1 == 0 and all(L[2*j]+1 == L[2*j+1] for j in range(m>>1)) print([k for k in range(10**5) if ok(k)]) # Michael S. Branicky, Aug 25 2025
Comments