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}$
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}$
On
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:
These together are enough to assemble the answer.
On
Let $s = \sum_{k=0}^{p}x^k$. Calculate $0 \leq a_1, a_2 < 5$, where $$ a_1 \equiv s \pmod 2 \\ a_2 \equiv s \pmod 5 $$
$a_1$ is easy. If $x \equiv_2 0$, then $a_1 = 1$, else $a_1 \equiv_2 (1+p)$, cause it's $1 + 1^1 + 1^2 + 1^3 + \dots + 1^p$.
$a_2$ isn't harder, $x \equiv_5 0, 1$ are same. For $2, 3, 4$ you can easily observe regularity. Eg. $$ x \equiv_5 2 \Longrightarrow\\ s \equiv_5 1 + 2^1 + 2^2 + \dots + 2^{p} \equiv_5 \\ 1 + 2 + 4 + 8 + \dots + 2^{p} \equiv_5 \\ 1 + 2 + 4 + 3 + 1 + 2 \dots + 2^{p} \equiv_5\\ (1 + 2 + 4 + 3) + 1 + 2 \dots + 2^{p} \equiv_5\\ 2 \cdot 5 + 1 + 2 \dots + 2^{p} $$
If you know $a_1, a_2$ you can use Chinese remainder theorem, to calculate number $r \equiv_{10} s$ and it's last digit.
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:
The following cases are a little more complicated: