OFFSET
1,1
COMMENTS
Proof: If n is of the form 2^k-1, then there are no smaller numbers with the same Hamming weight as n and a(n) = A057168(n) = (3n+1)/2.
If n is of the form (2^k-1)*2^m for some k,m>0, then n in binary is of the form 11..1100..00 and A057168(n) = 2^(k+m)+2^(k-1)-1, i.e. 100..0011..11 in binary. On the other hand, A243109(n) = (2^(k-1)-1)*2^(m+1)+2^(m-1), i.e. 11..110100..00 in binary. Thus A057168(n)-n = 2^(k-1)-1+2^m >= 2^m and n-A243109(n) = 2^(m-1) < 2^m. There is no tie and a(n) = A243109(n).
If n is not of the form (2^k-1)*2^m, then n in binary is of the form xxx...xxx0yyy...yyy, where xxxxxx and yyyyy are both not all zeros. If yyy...yyy is of the form 2^r-1, then A243109(n) must flip one of the '1' bit in xxx...xxx whereas A057168(n) leaves xxx...xxx unchanged. Thus n-A243109(n) > A057168(n)-n. Otherwise A057168(n) and A243109(n) will not change the bits xxx...xxx and reduces to the problem for yyy...yyy and thus the result follows by induction.
LINKS
Robert Israel, Table of n, a(n) for n = 1..10000
Marc B. Reynolds, Popcount walks: next, previous, toward and nearest (2023).
FORMULA
MAPLE
f:= proc(n) local t, k, d;
if n::even then d:=-1 else d:= 1 fi;
t:= convert(convert(n, base, 2), `+`);
for k from n+d by d do
if convert(convert(k, base, 2), `+`) = t then return k fi
od
end proc:
map(f, [$1..100]); # Robert Israel, Jun 20 2025
PROG
(Python)
def A381764(n): return n^((a:=-n&n+1)|(a>>1))
CROSSREFS
KEYWORD
nonn
AUTHOR
Chai Wah Wu, Mar 06 2025
STATUS
approved
