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}$ 

We'll work it out mod 5 and mod 2. We'll assume $p > 2$.
Mod 2, we have $x^i \equiv x$ for all $i$, except for $x^0$. Therefore the parity of the sum is just the same as the opposite of that of $x$ [unless $p=2$].
Mod 5: if $x \equiv 0 \pmod{5}$ then the result is certain to be $1$ mod $5$. Otherwise, $x^4 \equiv 1 \pmod{5}$, so we just have lots of expressions $1+x+x^2+x^3$ all added together; this is $4$ if $x \equiv 1 \pmod{5}$, and $0$ otherwise.
Hence:


*

*If $x$ is $0$ mod 5, the result is 1 mod 5.

*If $x$ isn't 1 mod 5, we'll get $1+x \pmod{5}$ if $p$ is $1$ mod 4, and $1+x+x^2+x^3 = 0$ if $p$ is $3$ mod 4.

*If $x$ is 1 mod 5, we'll get $-(p-1)/4 + (1+x) \pmod{5}$ if $p$ is $1$ mod 4, and $-(p+1)/4 \pmod{5}$ if $p$ is $3$ mod 4.


These together are enough to assemble the answer.
