Why are primes raised to the fourth power mod 10 equal to 1 I was just messing around with things, and found that a lot of prime numbers raised to the fourth power mod 10 are 1. This means that they end in the digit 1 (in base 10). I made a desmos graph demonstrating this, anybody have any idea why this is the case? I can't really understand why such a pattern would arise.
Here is the link to the desmos example by the way. I generated a bunch of random prime numbers and put them into a plot.
Even more, this is not a global property. As only 974 elements in my 1000 element list of primes becomes 1.
 A: This is a well known phenomenon that although a number $a$ can have any remainder modulo given numner $n$, it's power $a^k$ can have only a few of them. For example, if we consider the remainders modulo 3 we get the table:
$$\begin{array}{c|c}a&a^2\\\hline 0&0\\1&1\\2&1\end{array}$$
As we see, $a^2$ never gives $2$ as a remainder modulo $3$.
Let's consider another example, when we consider the remainder modulo $5$ of fourth powers of integers. Here's the table:
$$\begin{array}{c|c}a&a^4\\\hline 0&0\\1&1\\2&1\\3&1\\4&1\\\end{array}$$
Now you can consider the similar table in your case: fourh power, division by $10$:
$$\begin{array}{c|c}a&a^4\\\hline 0&0\\1,3,7,9&1\\2,4,6,8&6\\ 5&5\end{array}$$
As you see, if $2\nmid a$ and $5\nmid a$ then $a^4\equiv 1\pmod{10}$.
Fermat's little theorem If $p$ is prime and $p\nmid a$ then $a^{p-1} \equiv 1 \pmod p.$
From the theorem we get that if $5\nmid a$ then $a^4 \equiv 1 \pmod 5$ and therefore $a^4 \equiv 1 \pmod {10}$ or $a^4 \equiv 6 \pmod {10}$ The latter is impossible for odd numbers.
Remark. This phenomenon is often exploited on math competitions.
A: If $p$ is odd and is not divisible by $5$ then it's last digit is $1,3,7,$ or $9$.  $3 = \sqrt{10-1}$ and $7 = 10 - \sqrt{10-1}$ and $9=10-1$.
So $p\equiv \pm 1$ or $p\equiv \pm \sqrt{10-1}$ for all odd numbers not divisible by $5$.
So $p^4 \equiv (\pm 1)^4 \equiv 1 \pmod {10}$ or $p^4\equiv (\pm\sqrt{10-1})^4\equiv (10-1)^2\equiv (-1)^2 \equiv 1 \pmod {10}$.
And that's it.
Now admittedly I could have mad this simpler and just done $1^4 =1$ and $3^4=81\equiv 1$ and $7^4\equiv 49^2\equiv 9^2\equiv 81\equiv 1$ and $9^4 \equiv 81^2 \equiv 1^2$ but I want to show why they all work.
