Let $p > 0$ be a fixed prime. The $p$-adic metric (as defined in my class) on $\mathbb{Z}$ is given by $d : \mathbb{Z}^2 \to \mathbb{R}$ which is defined by $$d(m, n) = \begin{cases} 0 \ \ \ \ \text{if} \ \ \ m =n\\ \frac{1}{r} \ \ \ \text{if} \ \ \ m-n = p^{r-1}k \ \ \text{where $r, k \in \mathbb{Z}$ and $k$ is not divisible by $p$} \end{cases} $$
Now my question is the following, how do we know that $d$ is a well-defined function? By this I mean that for any $m, n \in \mathbb{Z}$ with $m \neq n$ how do we know that there exists an $r$ (in $\mathbb{Z}$?) such that $m-n = p^{r-1}k$ for our chosen fixed prime $p$ and a unique $k \in \mathbb{Z}$ such that $k$ is not divisible by $p$?
I'm assuming that uniqueness of $k$ is vital to well-definedness of $d$, since if $k$ was not unique there might exists another $r_0 \neq r$ such that $d(m, n) = \frac{1}{r_0} = \frac{1}{r}$ so $d$ wouldn't even be a function.
Abstracting from the difference (and sign) involved, for every positive integer $s$, there exists unique $r\ge 1$ and $k$ not divisible by $p$ such that $s=p^{r-1}k$. (We do not need to require that $p$ is prime for this; any integer $p>1$ would work).
First, such $r$ is unique because $p^{r-1}k=p^{r'-1}k'$ with wlog $r>r'$ would imply $p^{r-r'}k=k'$ where the left hand side is a multiple of $p$ and the right hand side is not.
Existence follows by induction on $s$: Existence of $r$ and $k$ is clear (namely, $r=1$ and $k=s$) for $1\le s<p$. For $s\ge p$,
Alternatively:
The set $\{\,r\in\Bbb N : p^{r-1}\text{ divides } m-n\,\}$ is not empty (because it contains $r=1$) and finite (because the non-zero integer $m-n$ has only finitely many divisors), hence has a maximal element.