Recursive Exponents $s^{(s-1)^{(s-2)^{...(0)}}}$

87 Views Asked by At

for $1 \leq S \leq 10^9$ I need $S^{(S-1)^{(s-2)^{...^{1}}}} \mod{n}$

and there must be a way which a program written based on that returns the result for $S = 10^9$ in less than a second.

what is the efficient answer?