For base $10$ natural number $n$, how would one find the base that represents $n$ in the minimum (number of digits) + (the number of digits in base $b$)?
This is for a programming project related to data compression, I am not much of a mathematician. This is not from a book or homework, this is something I need for a programming project.
My question: is there an accepted way to do this or a proven solution that already exists?
My steps for attempting to solve the problem ($b$ is the base):
$\text{total_digits} = \log_b(n) + 1 + \log_b(10)$
(from How to determine the number of digits needed to represent a number in different bases?)
Then we want to minimize $ \log_b(n) + 1 + \log_b(10) + \log_b(n) + 1 $
We want minimum value of this expression. Taking the derivative of this expression with respect to $b$ and setting it equal to zero gives us:
$$\frac{\ln(b) / \ln(10)}{\left(\ln(b) / \ln(10)\right)^2 + 1/n} = \log_b(e)$$
Denominator of the left side of equation is always greater than $1/n$, drop the $1/n$ term to get:
$$\frac{\ln(b) / \ln(10)}{\left(\ln(b) / \ln(10)\right)^2 + 1} \approx \log_b(e)$$
$$\implies \left(\frac{\ln(b)}{\ln(10)}\right)^2 \approx \frac{\ln(b)}{\ln(10)} + \log_e(n)$$
Let $x = \ln(b) / \ln(10)$ and $y = \log_e(n)$, then
$$x^2 - x - y \approx 0$$
$$\implies x = \frac{1 + \sqrt{1 + 4y}}{2}$$
Substituting the value of $x$ back in:
$$\ln(b) = \frac{\ln(10)}{2} \left( \sqrt{1+4\ln_e(n)} - 1 \right)$$
Solve for $b$:
$$b \approx e^{\frac{\ln(10)}{2}(1 + \sqrt{1 + 4\ln_e(n)})} \implies x \sqrt{10} e^{\frac{1}{2}\ln(10)\sqrt{1 + 4\ln_e(n)}} \implies \lceil \sqrt{10n} \rceil$$
Please let me know if I made a mistake somewhere. However, something else this solution is lacking is that often the answer is not a valid base for n. How do I find the base that represents $n$ in the minimum (number of digits )+ (num digits in base) while ensuring that the base is valid?
Thank you!