Last Digit of $x^0 + x^1 + x^2 + \cdots + x^{p-1} + x^p$ 
Given $x$ and $p$. Find the last digit of $x^0 + x^1 + x^2 + \cdots + x^{p-1} + x^p$    

I need a general formula. I can find that the sum is equal to
$\dfrac{x^{p+1}-1}{x-1}$
But how to find the last digit. 
P.S: $x\leq 999999$ and $p \leq 10^{15}$ 

Assuming that $x>0$.
Let $d$ denote the last digit of the series.
You can split the answer into $10$ different cases.

The following cases are rather simple:


*

*$x\equiv0\pmod{10} \implies d=1$

*$x\equiv1\pmod{10} \implies d=(1+p)\bmod{10}$

*$x\equiv4\pmod{10} \implies d=1+4(p\bmod{2})$

*$x\equiv5\pmod{10} \implies d=1+5(p\bmod{2})$

*$x\equiv9\pmod{10} \implies d=1-1(p\bmod{2})$



The following cases are a little more complicated:


*

*$x\equiv2\pmod{10} \implies d=\frac{-4(p\bmod{4})^3+15(p\bmod{4})^2-5(p\bmod{4})+3}{3}$

*$x\equiv3\pmod{10} \implies d=\frac{+1(p\bmod{4})^3-9(p\bmod{4})^2+17(p\bmod{4})+3}{3}$

*$x\equiv6\pmod{10} \implies d=\frac{-5(p\bmod{5})^4+40(p\bmod{5})^3-100(p\bmod{5})^2+83(p\bmod{5})+3}{3}$

*$x\equiv7\pmod{10} \implies d=\frac{+1(p\bmod{4})^3-15(p\bmod{4})^2+35(p\bmod{4})+3}{3}$

*$x\equiv8\pmod{10} \implies d=\frac{+11(p\bmod{4})^3-54(p\bmod{4})^2+67(p\bmod{4})+3}{3}$

