Explanation of the formulas for sums $\sum nr^n$ and $\sum n^2 r^n$
if $|x|<1$ then Geometric series says: \begin{equation}\sum_{k=0}^{\infty}x^k=\dfrac{1}{1-x}\qquad (1)\end{equation} In your case substitute $n-1=s$ and then use it.
Derivating $(1)$ we get \begin{align*}\sum_{k=0}^{\infty}kx^{k-1}&=\dfrac{1}{(1-x)^2}\\ \iff\sum_{k=1}^{\infty}kx^{k-1}&=\dfrac{1}{(1-x)^2} \end{align*}
Now multiply by $x$ $$\sum_{k=1}^{\infty}kx^{k}=\dfrac{x}{(1-x)^2}$$
Derivate again
$$\sum_{k=1}^{\infty}k^2x^{k-1}=-\dfrac{x+1}{(x-1)^3}$$