\(\(\(\ \)\(The\ distribution\ of\ \ n\^\(n\^\(n\^\(n\^\(n⋰\^n\)\)\)\)\ \((mod\ 10\^\(\(s\)\(\ \)\))\)\)\)\)

\(\(\(\(-The\)\ fastest\ Algorithm\ to\ calculate\ \ n\^\(n\^\(n\^\(n\^\(n⋰\^n\)\)\)\)\ \((mod\ 10\^\(\(s\)\(\ \)\))\)\)\(-\)\)\)

Kazuaki Fujii 
Ryohei Miyadera

1.Introduction.  We are going to study the  number (n^((n^((n^((n^(n(⋰^n))))))))), where we use n n-times. This number can be expressed as n↑↑n by the Knuth's arrow notation.  We found a very interesting fact that n↑↑n (mod (10^(s ))) depends only on  n (mod 2×(10^(s ))).  In particular n↑↑n (mod 10) depends only on  n (mod 20).  This is a very amazing and useful fact.  Once you calculate n↑↑n (mod 10) for n = 1,2,3⋯,20, then you can calculate n↑↑n (mod 10) for any number n by calculating n (mod 20).
    This number has been studied by many people.  See Eric W. Weisstein et al[1]. It is well known that the number n↑↑n can be very big if n ≥ 4.  When n = 4, this number has approximately 8.072304726028225`*^153 digits.  As  n increases, this number becomes bigger and bigger and even the most powerful conmputers cannot calculate it correctly.  
    Many people have tried to find a good algorithm to calculate n↑↑n(mod m), where m is a arbitrary number.  You can find good algorithms in Ilan Vardi[4].  
    Our algorithm is in a sense the fastest in calculating n↑↑n (mod (10^(s ))) when s is not so big.  For example once we make a chart by calculating n↑↑n (mod 10) for n = 1,2,3⋯,20, then you can calculate n↑↑n (mod 10) for any number n by calculating n (mod 20).  This in no doubt the fastest in calculating n↑↑n (mod 10).
    In our article we denote by Mod[p,q] the least nonnegative residue of the number p under modulus q, and hence Mod[p,q] = Mod[r,q] if and only if p ≡ r (mod q).  Although the expression p ≡ r (mod q) looks more familiar to many readers, the expression Mod[p,q] = Mod[r,q] is more convenient for us to represent our results.
    Throughout this article we let  λ be  the Carmichael function.  We denote by (λ^k)(t) the value we get after applying the function λ k-times.
    We added Mathematica calculations for formulas in this article.  Calculation by computers cannot substitute mathematical proof, but it is one of the most effective way to check the correctness of formulas.  In fact we sometimes corrected mistakes after the calculations.  We write Mathematica calculation in blue.

In the following lemmas  s  and  u are arbitrary nonnegative integers.

Lemma 1.  Let  λ be  the Carmichael function. 　The function has the following properties.
(a) Mod[(n^(λ(q))),q] = 1  for any positive integers  n and q such that q ≥ 2 and n is relatively prime to q.
λ((5^s)×(2^u))={({{4×(5^(s - 1))for any positive integer s and integer u=0,1,2,3.}, {(2^(u - 2))×(5^(s - 1))for any positive integer s and integer u ≥4.}})
(c)  λ(4)=2 and λ(2)=1.
(d)   (λ^k)((2^m)×(5^m)) =  (({{(2^Max)[2, m - 2  k]×(5^(m - k))  ( k < m)}, {\(2\^2\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \((\ 
                      k = m)\)\)}, {\(2\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \((\ k = m + 1)\)\)}, {1                           ( k ≥ m + 2)}}))for positive integers k and m.

Mathematica calculation for  Lemma 1.

The above relations are complicated, so it is a good thing to check them by calculation of Mathematica. 
(a) is a famous property of CarmichaelLambda[n].

(b) We are going to check the equation by calculation.

f1[s_, u_]:=CarmichaelLambda[(2^u)×(5^s)];
f2[s_, u_]:=If[0 ≤ u ≤ 3,4×(5^(s - 1)),(2^(u - 2))×(5^(s - 1))];
Table[f1[s, u] - f2[s, u], {s, 1, 10}, {u, 1, 10}]

(c)and (d).   We are going to check the equation by calculation.

CarmichaelLambda[4]
CarmichaelLambda[2]

g1[m_, k_]:=Nest[CarmichaelLambda,(5^m)×(2^m),k];
g2[m_, k_]:=Which[k < m,(2^Max)[2, m - 2  k]×(5^(m - k)) ,k == m,(2^2),k == m + 1,2,k ≥ m + 2,1];

Table[g1[m, k] - g2[m, k], {m, 1, 10}, {k, 1, 10}]

Proof.      (a), (b) and (c) are famous properties of the Carmichael function, so we are going to omit the proof.  
From (b) and (c) we have the following equations.
For positive integer k and v
(λ^k)((2^(2  v))×(5^(2  v)))  =   (({{(2^(2  v - 2  k))×(5^(2  v - k))  ( 
                  k < v - 1)}, {(2^2)×(5^(2  v - k))              ( 
                  k = v - 1)}, {(2^2)×(5^(2  v - k)) ( 
                  v - 1 < k ≤ 2  v)}, {(2^(2  v + 2 - k))(k = 2  v + 1)}, {1(k ≥  2  v + 2)}})).
For positive integer  k and non negative integer v
 (λ^k)((2^(2  v + 1))×(5^(2  v + 1))) = (({{(2^(2  v + 1 - 2  k))×(5^(2  v + 1 - k))  ( 
                  k ≤ v - 1)}, {\(2\^2×5\^\(2  v + 1 - k\)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \((\ k = v)\)\)}, {(2^2)×(5^(2  v + 1 - k)) ( 
                      v ≤ k ≤ 2  v + 1)}, {(2^(2  v + 3 - k))(k = 2  v + 2)}, {1 (k ≥ 2  v + 3)}})).
It is easy to get (d) from these equations.  If k≥m+2 and m is even, then
k≥ 2v+2.  Therefore by the first equation we have (λ^k)((2^m)×(5^m))=1.  If m is odd, we can use the second equation.  
If k = m + 1 or k = m, then we can similary use these two equations.
If k < m, we use the first equation for k < 2v and the second for k < 2v+1.
Then we have  (λ^k)((2^m)×(5^m))= (2^Max)[2, m - 2  k]×(5^(m - k)).

Mathematica calculation for the proof of Lemma 1.

The relations we used in the proof are complicated, so it is a good thing to check them by calculation of Mathematica.

The first equation.

ff1[v_, k_]:=Nest[CarmichaelLambda,(2^(2  v))(5^(2  v)),k];
ff2[v_, k_]:=Which[k < v - 1,(2^(2  v - 2  k))×(5^(2  v - k)) ,k == v - 1,(2^2)×(5^(2  v - k)),v - 1 < k ≤ 2  v,(2^2)×(5^(2  v - k)),k == 2  v + 1,(2^(2  v + 2 - k)),k ≥  2  v + 2,1];
Table[ff1[v, k] - ff2[v, k], {v, 1, 10}, {k, 1, 10}]

The second equation.

gg1[v_, k_]:=Nest[CarmichaelLambda,(2^(2  v + 1))×(5^(2  v + 1)),k];
gg2[v_, k_]:=Which[k ≤ v - 1,(2^(2  v + 1 - 2  k))×(5^(2  v + 1 - k)) ,k == v,(2^2)×(5^(2  v + 1 - k)),v ≤ k ≤ 2  v + 1,(2^2)×(5^(2  v + 1 - k)),k == 2  v + 2,(2^(2  v + 3 - k)),k ≥ 2  v + 3,1];
Table[gg1[v, k] - gg2[v, k], {v, 0, 10}, {k, 1, 10}]

Lemma 2. For any positive integer t relatively prime to 10 and for any positive number  m  
Mod[(t^m),(5^s) (2^u)] = Mod[(t^Mod)[m, λ((5^s) (2^u))],(5^s) (2^u)].

Proof. By Lemma 1(a) we have Mod[(t^(λ((5^s) (2^u)))),(5^s) (2^u)] = 1, which concludes the proof.

Mathematica calculation for Lemma 2.

t = 7;m = 6;Table[Mod[(t^m), (5^s) (2^u)]-Mod[(t^(Mod[m,CarmichaelLambda[(5^s) (2^u)]])),(5^s) (2^u)],{s, 0, 5},{u, 0, 5}]

Remark. By Lemma 2 we have 
Mod[(t^(m + u)),(5^s) (2^u)] = Mod[(t^(Mod[m, λ((5^s) (2^u))] + u)),(5^s) (2^u)] 
and 
Mod[(t^(m + s)),(5^s) (2^u)] = Mod[(t^(Mod[m, λ((5^s) (2^u))] + s)),(5^s) (2^u)].  
We need these equations later in our article.

Lemma 3. For any positive integer k and m  we have 
Mod[((((2^k)))^(m + u)),(5^s) (2^u)] = Mod[\(TraditionalForm\`\((2\^k)\)\^\(Mod[m, λ(\(5\^s\) 2\^u)] + u\)\),(5^s) (2^u)].

Proof.  By Lemma 1 we have Mod[((((2^k)))^(λ((5^s)))),(5^s)]=1.  Since λ((5^s) (2^u))is a multiple of λ((5^s)), we get Mod[((((2^k)))^(λ((5^s) (2^u)))),(5^s)]=1, and hence we have 
                  Mod[((((2^k)))^(λ((5^s) (2^u))))((((2^k)))^u),(5^s)]= Mod[((((2^k)))^u),(5^s)]....(1)
    Clearly we have 
                   Mod[((((2^k)))^(λ((5^s) (2^u))))((((2^k)))^u),(2^u)]= Mod[ ((((2^k)))^u),(2^u)]....(2)
Therefore by (1) and (2) we have 
Mod[((((2^k)))^(λ((5^s) (2^u))))((((2^k)))^u),(5^s) (2^u)]= Mod[((((2^k)))^u),(5^s) (2^u)], 
by which we have
Mod[((((2^k)))^(m + u)),(5^s) (2^u)] = Mod[\(TraditionalForm\`\((2\^k)\)\^\(Mod[m, λ(\(5\^s\) 2\^u)] + u\)\),(5^s) (2^u)].

Remark. The above  proof was suggested by Ask Dr.Math.dr.math@mathforum.org

Mathematica calculation for Lemma 3.

Table[Mod[((((2^k)))^(m + u)),(5^s) (2^u)]-Mod[((((2^k)))^(Mod[m,CarmichaelLambda((5^s) (2^u))]+u)),(5^s) (2^u)],{m, 1, 4},{k, 1, 4},{s, 0, 3},{u, 0, 3}]

Lemma 4. For any positive integer h and m  
Mod[((((5^h)))^(m + s)),(5^s) (2^u)] = Mod[\(TraditionalForm\`\((5\^h)\)\^\(Mod[m, λ(\(5\^s\) 2\^u)] + s\)\),(5^s) (2^u)].

Proof.  By Lemma 1 we have Mod[((((5^h)))^(λ((2^u)))),(2^u)]=1 for any positive integer.  Since λ((5^s) (2^u))is a multiple of λ((2^u)), we get Mod[((((5^h)))^(λ((5^s) (2^u)))),(2^u)]=1, and hence we have 
                    Mod[((((5^h)))^(λ((5^s) (2^u))))((((5^h)))^s),(2^u)]= Mod[((((5^h)))^s),(2^u)]....(1)
    Clearly we have Mod[((((5^h)))^(λ((5^s) (2^u))))((((5^h)))^s),(5^s)]= Mod[ ((((5^h)))^s),(5^s)]....(2)
Therefore by (1) and (2) we have Mod[((((5^h)))^(λ((5^s) (2^u))))((((5^h)))^s),(5^s) (2^u)]= Mod[((((5^h)))^s),(5^s) (2^u)], by which we have for any positive integer m
Mod[((((5^h)))^(m + s)),(5^s) (2^u)] = Mod[\(TraditionalForm\`\((5\^h)\)\^\(Mod[m, λ(\(5\^s\) 2\^u)] + s\)\),(5^s) (2^u)].

Mathematica calculation for Lemma 4.

Table[Mod[((((5^h)))^(m + s)),(5^s) (2^u)]-Mod[((((5^h)))^(Mod[m,CarmichaelLambda[(5^s) (2^u)]]+s)),(5^s) (2^u)],{m, 1, 4},{h, 1, 4},{s, 0, 3},{u, 0, 3}]

Lemma 5. For any positive integer n relatively prime to 5 
Mod[(n^(m + u)),(5^s) (2^u)] = Mod[(n^(Mod[m, λ((5^s) (2^u))] + u)),(5^s) (2^u)].

Proof.  Since n is relatively prime to 5, there exist a nonnegative number k and a positive number t such that t is relatively prime to 10 and  n=(2^k)×t.  By Lemma 3 and the remark to Lemma 2 we have  
Mod[((((2^k)×t))^(m + u)),(5^s) (2^u)] = Mod[\(TraditionalForm\`\((2\^k×t)\)\^\(Mod[m, λ(\(5\^s\) 2\^u)] + u\)\),(5^s) (2^u)], 
which concludes the proof.

Mathematica calculation for Lemma 5.

n5 = Select[Table[n, {n, 1, 20}], Mod[#, 5] > 0 &];

Table[Mod[n5[[x]]^(m + u),(5^s) (2^u)]-Mod[((n5[[x]])^(Mod[m,CarmichaelLambda[(5^s) (2^u)]]+u)),(5^s) (2^u)],{m, 1, 4},{x, 1, Length[n5]},{s, 0, 3},{u, 0, 3}]

Lemma 6. For any positive integer m and any odd integer n that is a multiple of 5  Mod[(n^(m + s)),(5^s) (2^u)] = Mod[(n^(Mod[m, λ((5^s) (2^u))] + s)),(5^s) (2^u)].
In particular if m > s, we have 
Mod[(n^m),(5^s) (2^u)] = Mod[(n^((m - s) + s)),(5^s) (2^u)] = Mod[(n^(Mod[m - s, λ((5^s) (2^u))] + s)),(5^s) (2^u)].

Proof.  There exists positive integers t and h such that t is relatively prime to 10 and n = (5^h)×t.  By Lemma 2 and the remark to it we have
Mod[(t^(m + s)),(5^s) (2^u)] = Mod[(t^(Mod[m, λ((5^s) (2^u))] + s)),(5^s) (2^u)] ⋯(1).
By Lemma 4 we have
Mod[((((5^h)))^(m + s)),(5^s) (2^u)] = Mod[\(TraditionalForm\`\((5\^h)\)\^\(Mod[m, λ(\(5\^s\) 2\^u)] + s\)\),(5^s) (2^u)]⋯(2).
By (1) and (2) we have
Mod[(n^(m + s)),(5^s) (2^u)] = Mod[(n^(Mod[m, λ((5^s) (2^u))] + s)),(5^s) (2^u)].

Mathematica calculation for Lemma 6.

n5 = 
      Select[Table[n, {n, 1, 100}], 
        OddQ[#] && Mod[#, 5] == 0 &]

Table[Mod[n5[[x]]^(m + s),(5^s) (2^u)]-Mod[((n5[[x]])^(Mod[m,CarmichaelLambda[(5^s) (2^u)]]+s)),(5^s) (2^u)],{m, 1, 4},{x, 1, Length[n5]},{s, 0, 3},{u, 0, 3}]

Lemma 7. For any positive integer p and q  Mod[p,q] ≥ v implies that 
Mod[p-v,q]=Mod[p,q]-v.
The proof is clear from the definition of Mod[].

Lemma 8. For any positive integers n and m Mod[(n^m),q] = Mod[Mod[n, q]^m,q].

Since this is also a simple property of Mod[ ], we will omit the proof.

Theorem 1. Let w be a positive integer.  For any positive integer n such that n is relatively prime to 10 and n > w+1 we have 
Mod[n↑↑n,(10^w)]= Mod[(n^(Mod[(n^(Mod[(n^(( )^((⋰^(Mod[n,(λ^w)((10^w))]))))),(λ^2)((10^w))])),λ((10^w))])),(10^w)].

Proof. By Lemma 2 we have
Mod[n↑↑n,(10^w)]= Mod[(n^(n↑↑(n - 1))),(10^w)]

= Mod[(n^(Mod[n↑↑(n - 1),λ((10^w))])),(10^w)].
By Lemma 1 for any k there are non negative integers u and s such that (λ^k)((10^w))= (2^u)×(5^s), and hence we can use Lemma 1 for (λ^k)((10^w)).
Therefore by using the fact that n > w+1 we can use Lemma 2 repeatedly (w+1)-times, and we have 
Mod[n↑↑n,(10^w)]= 

Mod[(n^(Mod[(n^(Mod[(n^((  )^((⋰^(Mod[(n^(Mod[n↑↑(n - 
                                        w - 1),(λ^(w + 1))((10^w))])),(λ^w)((10^w))]))))),(λ^2)((10^w))])),λ((10^w))])),(10^w)]
....(1).  
         By Lemma 1 (λ^(w + 1))((10^w))= 2, and hence by the fact that n is odd we have Mod[n↑↑(n - w - 1),(λ^(w + 1))((10^w))]=Mod[n↑↑(n - w - 1), 2]=1....(2).  
    By (1) and (2) we can finish the proof of this theorem.

Theorem 2. Let n and w be positive integers such that n is a even integer relatively prime to 5 and n ≥(10^w).  Then Mod[n↑↑n,(10^w)]
=　Mod[(n^(Mod[(n^(Mod[(n^((  )^((⋰^(Mod[\(n\^\(\^\(\^Mod[n\^4, 20]\)\)\),(λ^(w - 2))((10^w))]))))),(λ^2)((10^w))])),λ((10^w))])),(10^w)]

Proof. Let n ≥ (10^w) and k < w-1, and hence n ≥ Max[k +3,(10^w)] ....(1)
By Lemma 1 
(λ^k)((10^w)) = (2^Max)[2, w - 2  k]×(5^(w - k))....(2)
and
(λ^(k + 1))((10^w)) = (2^Max)[2, w - 2  k - 2]×(5^(w - k - 1))....(3),
and hence by using Lemma 5 for u = Max[2,w-2k] we have
Mod[n↑↑(n - k),(λ^k)((10^w))]= Mod[(n^(Mod[
                  n↑↑(n - k - 1) - 
                    Max[2, w - 
                        2  k], (λ^(k + 
                          1)) ((2^w)×(5^w))] + 
                Max[2, w - 2  k])),(λ^k)((10^w))].
Since k < w-1, by (3) (λ^(k + 1))((10^w)) is a multiple of 5. 
Therefore by the fact that n is relatively prime to 5 and (1) we have
Mod[n↑↑(n - k - 1),(λ^(k + 1))((10^w))]> 0.
(λ^(k + 1))((10^w))=(2^Max)[2, w - 2  k - 2]×(5^(w - 
              k - 1))  is a multiple of (2^Max)[2, w - 2  k - 2]....(4).
Since n is even, n↑↑(n-k-1) is a multiple of (2^(n↑↑(n - k - 2))), which in turn is a multiple of (2^Max)[2, w - 2  k - 2], because by (1) n↑↑(n-k-2) ≥ (n^n)> (10^((10^w)))> (10^w) > Max[2,w-2k-2].
Therefore n↑↑(n-k-1) is a multiple of (2^Max)[2, w - 2  k - 2]....(5).
Therefore by (4) and (5) Mod[n↑↑(n - k - 1),(λ^(k + 1))((10^w))]is a multiple of (2^Max)[2, w - 2  k - 2], which is bigger than or equal to Max[2,w-2k].
Therefore  by Lemma 7 Mod[n↑↑(n - k - 1) - Max[2, w - 2  k],(λ^(k + 1))((10^w))]+Max[2, w - 2  k]= Mod[n↑↑(n - k - 1),(λ^(k + 1))((10^w))].
Therefore we have
Mod[n↑↑(n - k),(λ^k)((10^w))] = Mod[(n^(Mod[n↑↑(n - k - 1),(λ^(k + 1))((10^w))])),(λ^k) ((10^w))].
We can do this for k = 1,2,⋯w-2, and get the followig equation.  

Mod[n↑↑n,(10^w)]
=Mod[(n^(Mod[(n^(Mod[(n^(( )^((⋰^(Mod[(n^(Mod[n↑↑(n - 
                                        w + 1),(λ^(w - 1))((10^w))])),(λ^(w - 2))((10^w))]))))),(λ^2)((10^w))])),λ((10^w))])),(10^w)] 
....(6) 
By Lemma 1 
(λ^(w - 1))((10^w)) = (2^2)×5  and (λ^w)((10^w)) = (2^2), 
and hence by Lemma 5
Mod[n↑↑(n - w + 1),(λ^(w - 1))((10^w))]= Mod[(n^(Mod[n↑↑(n - w) - 2, (2^2)] + 
                2)),(λ^(w - 1))((10^w))].
Since n is even and n ≥ (10^w), n↑↑(n-w) is a multiple of (2^2), which implies that Mod[n↑↑(n - w) - 2, (2^2)] + 2= 2+2 = 4.
Therefore we have
Mod[n↑↑(n - w + 1),(λ^(w - 1))((10^w))]= Mod[(n^4),(λ^(w - 1))((10^w))]....(7).
We can complete the proof by (6), (7) the fact that (λ^(w - 1))((10^w)) = (2^2)×5 .

Theorem 3. (a) For any positive integers n and w such that n ≥ (10^w) and n is odd and a multiple of 5 we have 
Mod[n↑↑n,(10^w)]
 =Mod[(n^(Mod[(n^(Mod[(n^(( )^((⋰^(Mod[(n^(Mod[n,(λ^w)((10^w))])),(λ^(w - 1))((10^w))]))))),(λ^2)((10^w))])),λ((10^w))])),(10^w)].
(b) For any positive integer n ( n ≥ (10^w)) which is a multiple of 10 we have Mod[n↑↑n,(10^w)]= 0.

Proof. Let n ≥ (10^w).  
(a) Let k < w-1. Then n ≥ k +3 ....(1).
 By Lemma 1
(λ^k)((10^w))=(2^Max)[2, w - 2  k]×(5^(w - k))  ....(2),
and hence by Lemma 6 we have
Mod[n↑↑(n - k),(λ^k)((10^w))]= Mod[(n^(Mod[n↑↑(n - k - 1) - (w - 
                        k),(λ^(k + 1))((10^w))]+(w - k))),(10^w)].
Since k < w-1 by Lemma 1
(λ^(k + 1))((10^w)) is even, and hence by the fact that n is odd
Mod[n↑↑(n - k - 1),(λ^(k + 1))((10^w))]> 0.
By (1) n-k-2 ≥ 1, and hence
n↑↑(n-k-2) ≥ n ≥ (10^w) > w-k-1....(3).
Since n is a multiple of 5, n↑↑(n-k-1) is a multiple of (5^(n↑↑(n - k - 2))),
and hence by (3) n↑↑(n-k-1)is a multiple of (5^(w - k - 1))....(4).
By (2) and (4)
Mod[n↑↑(n - k - 1),(λ^(k + 1))((10^w))]is a multiple of (5^(w - k - 1)), which is bigger than or equal to w-k.
Therefore  by Lemma 7 Mod[n↑↑(n - k - 1) - (w - k),(λ^(k + 1))((10^w))]+(w - k)= Mod[n↑↑(n - k - 1),(λ^(k + 1))((10^w))].
Therefore we have
Mod[n↑↑(n - k),(λ^k)((10^w))]= Mod[(n^Mod)[
                n↑↑(n - k - 
                      1), (λ^(k + 
                        1)) ((2^w)×(5^w))],(λ^k)((10^w))].
We can do this for k = 1,2,⋯w-2, and get the following equation.  
Mod[n↑↑n,(10^w)]

 =Mod[(n^(Mod[(n^(Mod[(n^((⋰^(Mod[(n^(Mod[n↑↑(n - 
                                        w + 1),(λ^(w - 1))((10^w))])),(λ^(w - 2))((10^w))])))),(λ^2)((10^w))])),λ((10^w))])),(10^w)]
....(5).  
By Lemma 1 
(λ^(w - 1))((10^w)) = (2^2)×5  and (λ^w)((10^w)) = (2^2), 
and hence by using Lemma 6 for s = 1
Mod[n↑↑(n - w + 1),(λ^(w - 1))((10^w))]= Mod[(n^(Mod[n↑↑(n - w) - 1, (2^2)] + 
                1)),(λ^(w - 1))((10^w))]....(6).
Since n is odd, n↑↑(n-w) is odd, and hence Mod[n↑↑(n-w),(2^2)]≥1.
By Lemma 7 we have
Mod[n↑↑(n - w) - 1, (2^2)] + 1= Mod[n↑↑(n - w), (2^2)]....(7).
Since n is odd and λ(4) = 2, by Lemma 1(a)
Mod[n↑↑(n - w), (2^2)]= Mod[(n^Mod)[n↑↑(n - w - 1), 2], (2^2)]....(8).
Since n is odd, Mod[n↑↑(n-w-1),2]=1....(9).
By (5),(6),(7),(8) and (9) we have
 Mod[n↑↑n,(10^w)]
 =Mod[(n^(Mod[(n^(Mod[(n^(( )^((⋰^(Mod[(n^(Mod[n,(λ^w)((10^w))])),(λ^(w - 1))((10^w))]))))),(λ^2)((10^w))])),λ((10^w))])),(10^w)].

(b) The proof is obvious, so we omit it.

Theorem 4. Let n and w be positive integers such that n ≥ (10^w).  Then Mod[n↑↑n,(10^w)]depends only on Mod[n,(10^w)].

Proof.  By Lemma 8 for any positive integers n, m, q we have 
Mod[(n^m),q] = Mod[Mod[n, q]^m,q],
and hence for any positive integers k and w we have 
Mod[(n^m),(λ^k)((10^w))] = Mod[((Mod[n,(λ^k)((10^w))])^m),(λ^k)((10^w))].
Therefore by Theorem 1, 2 and 3  Mod[n↑↑n,(10^w)] depends on {Mod[n,(λ^k)((10^w))] for k = 1,2,⋯,w+1}.  Since λ((10^w)) is a multiple of (λ^k)((10^w)), Mod[n↑↑n,(10^w)]depends only on Mod[n,(10^w)].

Theorem 5. Let n and w be positive integers.  Then
Mod[n↑↑n,(10^w)]depends only on Mod[n,2×(10^w)].

Proof.  By Theorem 4  Mod[n↑↑n,(10^w)]depends only on Mod[n,(10^w)] when n ≥ (10^w).  It is obvious that Mod[n↑↑n,(10^w)]depends on Mod[n,(10^w)] when n < (10^w).  Therefore 
Mod[n↑↑n,(10^w)]depends only on Mod[n,2×(10^w)].

Mathematica function for Mod[n↑↑n,100].

By Theorem 1, 2 and 3  we can make a Mathematica function calculatemod[] to calculate Mod[\(n\^\(n\^\(n\^\(\^\(⋰\^\(n\^n\)\)\)\)\)\),100] for any n, and by Theorem 5 we know that we only have to calculate M[n,200] for n = 0,2,⋯,199.

calculatemod[n_] := 
      Which[GCD[n, 10] == 1, 
        Mod[Mod[n, 100]^Mod[Mod[n, 20]^Mod[n, 4], 20], 100], n == 2, 
        4, GCD[n, 5] == 1 && EvenQ[n], 
        Mod[Mod[n, 100]^Mod[Mod[n, 20]^4, 20], 100], 
        Mod[n, 5] == 0 && OddQ[n], 25, Mod[n, 10] == 0, 
        0]

Chart 1.  The chart for Mod[\(n\^\(n\^\(n\^\(\^\(⋰\^\(n\^n\)\)\)\)\)\),100].  With this chart you have the fastest algorithm to calculate Mod[\(n\^\(n\^\(n\^\(\^\(⋰\^\(n\^n\)\)\)\)\)\),100].

({{the values of  Mod[n, 
              100], \(the\ corresponding\ values\ of\ Mod[
              n\^\(n\^\(n\^\(\^\(⋰\^\(n\^n\)\)\)\)\), 
              100]\)}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,1,{({{4 (if n = 2)}, {36 (if n  >  2)}}),87,96,25,56,43,56,89}, {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 11, 16, 53, 36, 25, 
          16, 77, 76, 79}, {20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 0, 21, 96, 47, 76, 25, 
          76, 83, 96, 69}, {30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0, 31, 76, 13, 16, 25, 
          36, 17, 16, 59}, {40, 42, 42, 43, 44, 45, 46, 47, 48, 49, 0, 41, 56, 7, 56, 25, 
          96, 23, 36, 49}, {50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 0, 51, 36, 73, 96, 25, 
          56, 57, 56, 39}, {60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 0, 61, 16, 67, 36, 25, 
          16, 63, 76, 29}, {70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 0, 71, 96, 33, 76, 25, 
          76, 97, 96, 19}, {80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 0, 81, 76, 27, 16, 25, 
          36, 3, 16, 9}, {90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 91, 56, 93, 56, 25, 
          96, 37, 36, 99}})

Mathematica calculation for Chart 1.

calculatemod[n_] := 
      Which[GCD[n, 10] == 1, 
        Mod[Mod[n, 100]^Mod[Mod[n, 20]^Mod[n, 4], 20], 100], n == 2, 
        4, GCD[n, 5] == 1 && EvenQ[n], 
        Mod[Mod[n, 100]^Mod[Mod[n, 20]^4, 20], 100], 
        Mod[n, 5] == 0 && OddQ[n], 25, Mod[n, 10] == 0, 
        0]

a = 
      Table[Table[calculatemod[n], {n, 10  m, 10  m + 9}], {m, 0, 
          9}]

a2 = 
      Table[Table[calculatemod[n], {n, 10  m, 10  m + 9}], {m, 10, 
          19}]

a3 = 
      Table[Table[calculatemod[n], {n, 10  m, 10  m + 9}], {m, 20, 
          29}]

a2 - a

a3 - a2

Chart 2. The chart for Mod[\(n\^\(n\^\(n\^\(\^\(⋰\^\(n\^n\)\)\)\)\)\),10].  From the above chart we can see that Mod[\(n\^\(n\^\(n\^\(\^\(⋰\^\(n\^n\)\)\)\)\), 10\)](the last digit of \(n\^\(n\^\(n\^\(\^\(⋰\^\(n\^n\)\)\)\)\)\)) depends only on Mod[n,20].  From this fact we can make a chart of Mod[\(n\^\(n\^\(n\^\(\^\(⋰\^\(n\^n\)\)\)\)\), 10\)].

({{the values of  Mod[n, 
              20], \(the\ corresponding\ the\ values\ of\ Mod[
              n\^\(n\^\(n\^\(\^\(⋰\^\(n\^n\)\)\)\)\), 
              10]\)}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0,1,{({{4 (if n = 2)}, {6 (if n  >  2)}}),7,6,5,6,3,6,9}, {11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 6, 3, 6, 5, 6, 7, 6, 
          9}})

Mathematica calculation for Chart 2.

calculatemod[n_] := 
      Which[GCD[n, 10] == 1, 
        Mod[Mod[n, 100]^Mod[Mod[n, 20]^Mod[n, 4], 20], 100], n == 2, 
        4, GCD[n, 5] == 1 && EvenQ[n], 
        Mod[Mod[n, 100]^Mod[Mod[n, 20]^4, 20], 100], 
        Mod[n, 5] == 0 && OddQ[n], 25, Mod[n, 10] == 0, 
        0]

a = 
      Table[Table[Mod[calculatemod[n], 10], {n, 10  m, 10  m + 9}], {m, 0, 
          9}]

References  
Eric W. Weisstein et al [1]. "Power Tower."From MathWorld.
Eric W.Weisstein[2]."Carmichael Function."From MathWorld.
Eric W.Weisstein[3]. "Totient Function."From MathWorld.
Ilan Vardi[4], Computational Recreations in Mathematica
             Addison-Wesley (1991)