%I #48 Mar 14 2021 14:26:31
%S 0,1,3,3,5,5,7,7,9,9,11,11,11,11,15,15,17,17,19,19,19,19,19,19,19,19,
%T 23,23,23,23,31,31,33,33,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,
%U 35,39,39,39,39,39,39,39,39,47,47,47,47,63,63,65,65,67,67
%N a(n) is the least k such that the binary reversal of k is greater than or equal to n.
%C A030101 gives the binary reversal of a number.
%C All positive terms belong to A209492.
%C This sequence is nondecreasing.
%H Rémy Sigrist, <a href="/A340836/b340836.txt">Table of n, a(n) for n = 0..8192</a>
%F a(n) <= n + 1.
%e For n = 8:
%e - A030101(k) < 8 for any k <= 8,
%e - A030101(9) = 9 >= 8,
%e - so a(8) = 9.
%o (PARI) { base = 2; k = 0; r = 0; for (n=0, 67, while (r<n, r = fromdigits(Vecrev(digits(k++, base)), base);); print1 (k ", ")) }
%o (Python)
%o def A340836(n):
%o if n == 0:
%o return 0
%o s = bin(n)[2:]
%o i = s.find('0')
%o if i == -1:
%o return n
%o s1, s2 = s[:i+1], s[i+1:]
%o if s2 == '':
%o return n+1
%o if int(s2) <= 1:
%o return int('1'+s2[-2::-1]+s1[::-1],2)
%o else:
%o return int('1'+'0'*(len(s2)-1)+bin(int(s1,2)+1)[:1:-1],2) # _Chai Wah Wu_, Mar 14 2021
%Y Cf. A030101, A209492, A340835 (decimal analog).
%K nonn,base
%O 0,3
%A _Rémy Sigrist_, Mar 13 2021