OFFSET
0,6
COMMENTS
Equivalently the distance to the nearest integer that can be added without carries in base 2.
LINKS
FORMULA
EXAMPLE
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.
PROG
(PARI) a(n) = { my (high=2^#binary(n), low=high-1-n); min(n-low, high-n) }
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Apr 27 2022
STATUS
approved