A353157 a(n) is the distance from n to the nearest integer whose binary expansion has no common 1-bits with that of n.
0, 1, 1, 1, 1, 3, 2, 1, 1, 3, 5, 5, 4, 3, 2, 1, 1, 3, 5, 7, 9, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25
Offset: 0
Examples
For n = 42 ("101010" in binary): - 21 ("10101") is the greatest number <= 42 that has no common 1-bits with 42, - 128 ("1000000") is the least number >= 42 that has no common 1-bits with 42, - so a(42) = min(42-21, 128-42) = min(21, 86) = 21.
Links
Programs
-
PARI
a(n) = { my (high=2^#binary(n), low=high-1-n); min(n-low, high-n) }
Comments