Expansions of a Real Number $x$ I am completely lost on what to do with the following problem.

Let $p$ be a natural number greater than $1$, and let $x$ be a real number with $0\leq x\leq 1$. Show that there is a sequence of integers $\{a_{n}\}$ with $0\leq a_{n}<p$ for each $n$ such that $x=\sum_{n=1}^{\infty}\frac{a_{n}}{p^{n}}$, and that the sequence is unique except when $x$ is of the form $\frac{q}{p^{n}}$, $0<p<q$, in which case there are exactly two such sequences.
Conversely, show that if $\{a_{n}\}$ is any sequence of integers with $0\leq a_{n}<p$, the series $\sum_{n=1}^{\infty}\frac{a_{n}}{p^{n}}$ converges to a real number $x$ with $0\leq x\leq 1$.

As I said, I am completely lost, so any help is appreciated!
 A: Let's assume for simplicity that $0\le x < 1$ ( the case $x=1$ can be treated separately).
So, given $x$, we can describe the procedure of finding $a_1$, $a_2$, $\ldots$ as follows.
Let's denote for uniformity $x_1=x$. We have $0\le x_1 < 1$ so 
$$0 \le p \cdot x_1 < p$$. 
Take $a_1$ to be the integral part of $p x_1$. It will be a number from the set $\{0, 1, \ldots, p-1\}$. We can write 
$$px_1 = a_1 + x_2$$, where $x_2$ is the fractional part of $px_1$, that is
$$a_1 = [p\cdot x_1]\\
x_2 =\{p \cdot x_1\}$$
In general, we define recursively
$$a_{n} = [p\cdot x_n]\\ x_{n+1} = \{p \cdot x_n\}$$ for all $n\ge 1$. 
We see that we have $a_n\in \{0,1,\ldots, p-1\}$ for all $n\ge 1$.  From the equalities above we get
$$x_{n} = \frac{a_n}{p} + \frac{x_{n+1}}{p}$$ for all $n\ge 1$. It follows that we have
$$x = x_1 = \frac{a_1}{p} + \frac{a_2}{p^2} + \cdots + \frac{a_n}{p^n} + \frac{x_{n+1}}{p^n}$$ for all $n$. Since $0\le x_{n+1} < 1$ we get 
$$0 \le x - \sum_{k=1}^n \frac{a_k}{p^k} < \frac{1}{p^n}$$
So we have a procedure to find the required writing of $x$ as a (potentially) infinite sum. (The procedure will stop if at some point we get $x_{n+1}=0$). 
I recommend finding some $x_n$'s and $a_n$'s for some concrete $p$ and $x$ ( say with a pocket calculator). 
