The title is a question itself.
Does exist any fast algorithm to get $$k^n \pmod{ka}$$ ?
($k, a, n > 1 $, natural number)
The title is a question itself.
Does exist any fast algorithm to get $$k^n \pmod{ka}$$ ?
($k, a, n > 1 $, natural number)
If we have $k,a>n$ we would probably just have to do the exponentiation, rather than reduce the exponent using Euler/Carmichael etc. - but it might be worth checking that (although probably not for an coded system). In particular if $a$ is composite with no small factors it may not be worth the time to determine its factors, since the exponentiation calculation is not very time-consuming anyway.
Assuming that any reduced exponent has been determined, calculate $k^{n-1} \bmod a$ using exponentiation by squaring, then multiply by $k$.
Note that you may need to handle intermediate values as large as $a^2$, if using simple multiplication.