How to calculate last four digits of $2^{2017}$?

can u suggest me any short trick of solving these kind of problems. How to find last four digits of any number raised to some power ?


Since $10^4 = 2^4 \times 5^4$, my first reaction is one should use Chinese remainder theorem.

For $2^4$, it is clear $2^{2017} \equiv 0 \pmod {2^4}$.

For $5^4$, we use following theorem

For $a,b \in \mathbb{Z}_{+}$ such that $\gcd(a,b) = 1$, we have $$a^{\varphi(b)} \equiv 1 \pmod b$$ where $\varphi(\cdot)$ is the Euler totient function.

For $a = 2$ and $b = 5^4$, we have $\varphi(5^4) = 4(5)^3 = 500$. This leads to $$2^{2017} = 2^{4(500)+17} \equiv 2^{17} \equiv 65536\times 2 \equiv 1072\pmod {5^4}$$

It turns out we are lucky. Since $1072 \equiv 0\pmod {2^4}$ already, we don't need CRT to conclude $2^{2017} \equiv 1072 \pmod {10^4}$. As a result, the last $4$ digits of $2^{2017}$ is $1072$.


Hint: You want to find $2^{2017} \bmod 10000$. To do that, it suffices to find it $\bmod 16$ and $\bmod 625$. Finding it $\bmod 16$ is easy; to find it $\bmod 625$, use Euler's theorem that, if $\gcd(a,n)=1$, then

$$a^{\varphi(n)} \equiv 1\bmod n,$$

where $\varphi(n)$ is the Euler totient function. Can this reduce $2^{2017}$ into something more manageable?


Like How to find last two digits of $2^{2016}$,

I shall find $2^{2017-4}\pmod{10^4/2^4}$

As $2^2=5-1$

$\displaystyle2^{2012}=(5-1)^{1006}\equiv1-\binom{1006}15+\binom{1006}25^2-\binom{1006}35^3\pmod{5^4}$

Now $\displaystyle1006\equiv6\pmod{5^3}\implies\binom{1006}15\equiv5\cdot6\pmod{5^4}$

$\displaystyle\binom{1006}2\equiv15\pmod{5^2}\implies\binom{1006}25^2\equiv5^2\cdot15\pmod{5^4}$

and $\displaystyle\binom{1006}3\equiv0\pmod5\implies\binom{1006}35^3\equiv0\pmod{5^4}$

$\displaystyle\implies2^{2012+1}\equiv2(1-5\cdot6+5^2\cdot15)\equiv346\cdot2\pmod{5^4}$

Multiply out by $2^4$