# 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.

• Any odd prime $\neq 5$ must be $\equiv 1, 3, 7, 9\pmod {10}$ So you need only compute each of those to the $4^{th}$ (or just note that $\varphi(10)=4$ and invoke little Fermat).
– lulu
Aug 11 at 21:04
• I tried expressing primes $>3$ base $6$ and when I square them, they all end in $1$. Now why might that be? (It's the modulo $6$ version of this problem.) Aug 11 at 21:13
• There must be some major flaw with your list of elements or with your computation, because $x$ is a multiple of $2$ or $5$ if and only if $x^4$ does not end with the digit $1$. Aug 11 at 21:13
• Or to put @Dan's comment into other words. For all odd prime not equal to $5$. Indeed it is true for all odd numbers not divisible by $5$. Aug 11 at 23:27
• "As only 974 elements in my 1000 element list of primes becomes 1." What is your $1000$ element list. If they are all odd and none divisible by 5 it should work. To have desmos miss only 26 out of 1000 is probably just a rounding error. Aug 11 at 23:31

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.

• @JohnOmielan, 👌 Aug 11 at 23:06

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.