It is well known, that
$$a^{\phi(m)}\equiv1\pmod m ,$$
if $\gcd(a,m)=1.$
So, $a^n\pmod m$ can be calculated by reducing n modulo $\phi(m)$.
But, for the tetration modulo $m$
$$a \uparrow \uparrow n\pmod{m},$$
I need the general case, where $a$ and $m$ need not to be coprime.
Which reduction can I use in this case ?
Is there an easier method to calculate the tetration modulo m without using the reductions modulo $m , \phi(m) , \phi(\phi(m)) ...$ ?
I tried to write a program in PARI, but I failed because reducing modulo $\phi(m)$ does not work, if a and m are not coprime.
The best you can say in general is $$a^k \equiv a^{k+\lambda(n)} \bmod n $$ for all $a$ (including those not co-prime to $n$) and all $k \geq \max v_p(n)$.
Here, $\lambda$ is Carmichael’s function and $v_p(n)$ is the exponent of $p$ in the prime factorization of $n$.