TITLE: Representation of a natrual number by the sum of geometric progression with minimal scale factor
QUESTION [5 upvotes]: This question is inspired by a leetcode question. Let's say we have a number $x$ and we want to represent it by a geometric progression. The easiest progression is $1+(x-1)$. But how to find the series with the minimal scaling factor? For example $13 = 1 + 12 = 1 + 3 + 9$ and $3$ is the right solution.
I tried somehow to work with the equation
$$\dfrac{r^n - 1}{r-1} = x,$$
and then I came to
$$r(x-r^{n-1}) = x-1,$$
which means that both $r$ and the other part has to be dividers of $x-1$.
I know how to make a numeric solution with a python script but how would a mathematician tackle this issue? Is there any formula which can help? I tried to google “representation of number by geometric progression” but did not find anything.

REPLY [2 votes]: At first, can be used the next conditions of divisibility:
\begin{align}
&r\ |\ x-1,\tag1\\
&r^{n-1}-1\ |\ x-1,\tag2\\
&x\ |\ r^n - 1,\tag3\\
\end{align}
so for the given $n$
\begin{align}
&r\in\left[\sqrt[n]{x+1}], \sqrt[n-1]x\ \right],\tag4\\
\end{align}
and constraints $(4)$ allows to optimize the program to the required $O(\log x).$