# What is $\underbrace{2018^{2018^{2018^{\mathstrut^{.^{.^{.^{2018}}}}}}}}_{p\,\text{times}}\pmod p$ where $p$ is an odd prime?

This recent question inspired me to explore values concerning modulo arithmetic of tetrations, and I thus pose the following question.

Is there a general expression for the value of $$\underbrace{2018^{2018^{2018^{\mathstrut^{.^{.^{.^{2018}}}}}}}}_{p\,\text{times}}\pmod p$$ where $p$ is odd prime?

We can write the tetration as $^p2018\pmod p$ - for details see here. Wolfram gives these first values: $$\begin{array}{c|c|c|c|c|c|c}p&3&5&7&11&13&17&19\\\hline ^p2018\pmod p&1&1&2&5&3&1&6\end{array}$$ Using FLT is out of the question for large $p$.

EDIT: Revisiting this question again, I have spotted a pattern in the table.

Claim

Let $q$ be the remainder of $\frac{{}^p2018}p$. Then \begin{align}p\equiv\left\{\begin{matrix} 0&\quad\text{if}\quad{}q=1\\ 1&\quad\text{otherwise} \end{matrix}\right.\pmod{q}\end{align}

As @didgogns has mentioned below, all known Fermat numbers satisfy the equality that $${}^p2018\pmod p=1$$

• I feel you are trying to find laws where there are none. Why not inquire for what primes you get an integer whose digits are in a predetermined order?. Regards. – Piquito Feb 12 '18 at 11:46
• @Piquito Two months later, I have found a pattern from the table. Please share your thoughts on this. – TheSimpliFire Apr 13 '18 at 19:25
• For all $m \ge 3$, $^m 2018 \equiv 1 \pmod 3$. Can you explain how your claim is true for $p=3$, $q=7$? – didgogns Apr 14 '18 at 15:01
• For Claim 2, remind that there are only 5 known Fermat primes and all of them satisfy $a^{65536}\equiv 1 \pmod p$. It is easy to see that $^{p-1}2018$ is multiple of $65536$. Therefore ${}^p2018\equiv (2018^{65536})^{\text{large number}}\equiv1\pmod p$ – didgogns Apr 14 '18 at 15:33
• There are no primes of form $2^n+1$ except the Fermat primes :) – didgogns Apr 14 '18 at 15:40

## 1 Answer

Unfortunately, your claim is not true. I'll prove that$$^{31} 2018 \equiv 28\pmod {31}$$ . Firstly, note that for all $n \geq 2$, $^n 2018$ is multiple of $4$. By Fermat's Little Theorem, we get $^{(n+1)}2018=2018^{^n 2018}\equiv2018^2\equiv1\pmod 3$ and $^{(n+1)}2018\equiv2018^4\equiv1\pmod 5$. It also holds for $n=29$, so $^{30} 2018 \equiv 0 \pmod2$, $^{30} 2018 \equiv 1 \pmod3$ and $^{30} 2018 \equiv 1 \pmod5$. By the Chinese Remainder Theorem, $^{30} 2018 \equiv 16 \pmod{30}$.

Now, $^{31} 2018 = 2018^{^{30} 2018} \equiv 2018^{16} \equiv 28\pmod {31}$.

• (+1) Nice! I have found something really interesting about this modulo $31$: the value of ${}^k2018\pmod{31}$ is $28$ for all $k>3$ but neither $2018^{19}\pmod{31}$ nor $19^{2018}\pmod{31}$ equal $28$... – TheSimpliFire Apr 16 '18 at 15:22
• Note that ${}^32018\pmod{31}=19$ – TheSimpliFire Apr 16 '18 at 15:26