Largest possible difference between "round numbers" (multiples of powers of 10) that contain a given interval

36 Views Asked by At

I came up with this problem while trying to write code to create limits for a plot that are nice round numbers, given an arbitrary range of data. I have an intuition that the answer is 10, but I can't quite prove it.

Problem Statement

Let $A$ and $B$ be two real numbers with $A < B$. Let $C$ be the largest power of $10$ that is less than or equal to $B - A$. Let $A'$ be the largest multiple of $C$ that is less than or equal to $A$, and $B'$ be the largest multiple of $C$ that is greater than or equal to $B$. What is the maximum possible value of $$ \frac{B' - A'}{C}? $$

Proof that the Answer is at Most $12$ $$ C = 10^{\lfloor \log_{10}(B-A) \rfloor} > 10^{\log_{10}(B-A) - 1} = \frac{B-A}{10} $$ and $A' = C\lfloor \frac{A}{C} \rfloor$ and $B' = C\lceil \frac{B}{C} \rceil$.

Therefore, $$ \frac{B'-A'}{C} = \biggl\lceil \frac{B}{C} \biggr\rceil - \biggl\lfloor \frac{A}{C} \biggr\rfloor < \frac{B}{C} + 1 - \biggl(\frac{A}{C} - 1\biggr) = \frac{B-A}{C} + 2 < \frac{B-A}{(B-A)/10} + 2 = 12 $$

Again, I'm pretty sure the answer here is actually $10$, but I'm not sure how to shave off that final $2$ in the proof.

1

There are 1 best solutions below

2
On BEST ANSWER

We have: $$B-A<10C$$ $$A-A'<C$$ $$B\,'-B<C$$ Adding these up, $$B\,'-A'<12C$$ And $B\,'-A'$ is a multiple of $C$, so $(B\,'-A')/C\le 11$.

And this is the best we can do: if $A=9$ and $B=108$, then $C=10$, and we get $A'=0, B\,'=110, (B\,'-A')/C=11$.