Hi,

How would one do to calculate something like a^b mod m where 0<a,b,m<10000?

Is there an efficient algorithm do to this? I have heard (and think I understand it) that the Euler totient (phi)-function can be used, but I'm not quite sure how.

And if we go one step further, and want to know a^b^c mod m, 0 < a,b,c,m < 10000, can we use some kind of recursive formula?

Thanks!

Alex