The following is a (long) problem from Chapter 23, "Infinite Series", from Spivak's Calculus. I am stuck on item (d), and my question is about that item. I am going to show you the whole problem statement, and then I will go through the solutions to items (a), (b), and (c). If you want to see the question directly, please skip to item (d) at the very bottom.
(a) Let $\{a_n\}$ be a sequence of integers with $0\leq a_n\leq 9$. Prove that $\sum\limits_{n=1}^\infty \left ( a_n\cdot10^{-n} \right )$ exists (and lies between $0$ and $1$). (This, of course, is the number which we usually denote by $0.a_1a_2a_3a_4...$)
(b) Suppose that $0\leq x\leq 1$. Prove that there is a sequence of integers $\{a_n\}$ with $0\leq a_n\leq 9$ and $\sum\limits_{n=1}^\infty \left (a_n\cdot 10^{-n}\right )=x$. Hint: For example, $a_1=[10x]$, where $[y]$ denotes the greatest integer which is $\leq y$.
(c) Show that if $\{a_n\}$ is repeating, i.e., is of the form $a_1,a_2,...,a_k, a_1, a_2,...,a_k,a_1, a_2,...$, then $\sum\limits_{n=1}^\infty \left (a_n\cdot 10^{-n}\right )$ is a rational number (and find it). The same result naturally holds if $\{a_n\}$ is eventually repeating, i.e., if the sequence $\{a_{N+k}\}$ is repeating for some $N$.
(d) Prove that if $x=\sum\limits_{n=1}^\infty \left (a_n\cdot 10^{-n}\right )$ is rational, then $\{a_n\}$ is eventually repeating. (Just look at the process of finding the decimal expansion of $p/q$ dividing $q$ into $p$ by long division).
Let me go through the solutions to (a)-(c) to prepare for item (d).
Item (a)
Let $\{b_n\}=\{a_n\cdot10^{-n}\}$. Then $\sum\limits_{n=1}^\infty b_n=\frac{a_1}{10}+\frac{a_2}{10^2}+\frac{a_3}{10^3}+...$.
For each $n$, the largest possible value $b_n$ can have is $\frac{9}{10^n}$, and the smallest value is $0$.
Thus, $$0=\sum\limits_{n=1}^\infty 0 \leq \sum\limits_{n=1}^\infty b_n \leq \sum\limits_{n=1}^\infty \frac{9}{10^n}=1$$
By the Boundedness Criterion (A nonnegative $\{a_n\}$ is summable $\iff$ the set of partial sums of $a_n$ is bounded), $\{b_n\}$ is summable, ie $\sum\limits_{n=1}^\infty \left ( a_n\cdot10^{-n} \right )$ exists.
Item (b)
Now, given an $x$ such that $0\leq x\leq 1$, we want to prove that there is a sequence $\{a_n\}$ such that $a_n\in\mathbb{Z}$, $0\leq a_n\leq 9$, and $\sum\limits_{n=1}^\infty \left ( a_n\cdot10^{-n} \right )=x$.
We can write such a number $x$ as a decimal as $0.n_1n_2n_3n_4...$, where $n_i$ is one of $0,1,2,...,9$.
The notation will be a bit loose below, but I think the intention will be very clear. When I write a number as $n_1n_2n_3.n_4n_5$, for example, it means it is the number $10^2n_1+10n_2+n_3+10^{-1}n_4+10^{-2}n_5$.
Then,
$$10x=n_1.n_2n_3...$$
$$[10x]=n_1=a_1$$
$$\frac{[10x]}{10}=0.n_1$$
Then,
$$10^2x=n_1n_2.n_3n_4...$$
$$[10^2x]=n_1n_2$$
$$[10^2x]-10a_1=n_2=a_2$$
$$\frac{[10^2x]-10*a_1}{10^2}=0.0n_2$$
If we go one step further we obtain
$$[10^3x]-10^2a_1-10a_2=n_3=a_3$$
and
$$\frac{[10^3x]-10^2a_1-10a_2}{10^3}=0.00n_3$$
The pattern is thus that we choose
$$a_k=[10^kx]-(10^{k-1}a_1+10^{k-2}a_2+...+10a_{k-1})=n_k$$
It seems clear from the above that $a_k=n_k$, an integer from $0$ to $9$. We could also show this as follows.
Let
$$a_k=[10^kx]-(10^{k-1}a_1+10^{k-2}a_2+...+10a_{k-1})\tag{1}$$
$$=[10^kx-(10^{k-1}a_1+10^{k-2}a_2+...+10a_{k-1})]$$
Then
$$0\leq 10^kx-(10^{k-1}a_1+10^{k-2}a_2+...+10a_{k-1}) -a_k< 1$$
$$0\leq 10^kx-(10^{k-1}a_1+10^{k-2}a_2+...+10a_{k-1}+a_k) < 1$$
Multiply by $10$
$$0\leq 10^{k+1}x-(10^{k}a_1+10^{k-1}a_2+...+10^2a_{k-1}+10a_k)=a_{k+1} < 10\tag{2}$$
I.e.
$$0\leq a_{k+1}<10$$
Which shows that each element in the sequence $\{a_n\}$ is one of $0,1,2,...9$.
Now we want to show that the infinite series $\sum\limits_{n=1}^\infty \left ( a_n\cdot10^{-n} \right )$ formed based on our newly defined $\{a_n\}$ converges to $x$.
Divide (2) by $10^{k+1}$ to obtain
$$0\leq x-(a_1 10^{-1}+a_2 10^{-2}+...+a_{n-1} 10^{1-n}+a_n 10^{-n})<10^{-n}$$
Since this is true for all $n$, then $x$ and $\sum\limits_{k=1}^n \left ( a_k\cdot10^{-k} \right )$ can be made arbitrarily close by increasing $n$.
Thus
$$\sum\limits_{n=1}^\infty \left ( a_n\cdot10^{-n} \right )=x$$
Item (c)
Our series is now repeating, and is thus
$$\sum\limits_{n=1}^\infty \left ( a_n\cdot10^{-n} \right )= \frac{a_1}{10}+ \frac{a_2}{10^2}+...+ \frac{a_k}{10^k}+ \frac{a_1}{10^{k+1}}+ \frac{a_2}{10^{k+2}}+...+ \frac{a_k}{10^{2k}}+...$$
$$=\sum\limits_{i=0}^\infty \frac{a_1}{10^{ik+1}}+\sum\limits_{i=0}^\infty \frac{a_2}{10^{ik+2}}+...+\sum\limits_{i=0}^\infty \frac{a_k}{10^{ik+k}}$$
Now,
$$\sum\limits_{i=0}^\infty \frac{a_n}{10^{ik+n}}=\frac{a_n}{10^2}\frac{1}{1-0.1^k}$$
Thus,
$$\sum\limits_{n=1}^\infty \left ( a_n\cdot10^{-n} \right )=\frac{1}{1-0.1^k}\left ( \frac{a_1}{10}+\frac{a_2}{10^2}+...+\frac{a_k}{10^k} \right )$$
$$=\frac{a_110^{k-1}+a_210^{k-2}+...+a_k}{10^k-1}$$
$$=x$$
which is therefore rational.
Item (d)
Now we assume that $x=\sum\limits_{n=1}^\infty \left ( a_n\cdot10^{-n} \right )$ is rational, and want to prove that the sequence $\{a_n\}$ is eventually repeating.
I will now show the solution manual solution verbatim for this item.
The number $a_n$ in part $(b)$ satisfies
$$0\leq \frac{10^n p}{q}-(10^{n-1}a_1+...+10a_{n-1}+a_n)<1$$
Now $10^np/q$ can be written as $k+r/q$ where $k$ is an integer and $0\leq r\leq q-1$. In this case $$a_{n-1}=[10r/q]\tag{3}$$
Since there are at most $q$ different fractions $r/q$, there will have to be some $m$ and $n$ with $m>n$ and $a_{n+1}=[10r/q]=a_{m+1}$. It is easy to see that we will then have $a_{n+2}=a_{m+2}$, etc.
My question is basically how to understand this solution. How is (3) obtained, for example?