Hi!
ack(7,7) = 2^2^2^2^2.... -3 (many many twos)
You have to calc
2^2^2^2^2.... -3 mod 7^7
Using Euler's theorem
http://en.wikipedia.org/wiki/Euler%27s_theorem (
a^phi(m) mod m = 1 when
a and
m are coprime) you can simplify this expression to:
2^(2^2^2^2.... mod phi(7^7)) mod 7^7, and now, the only problem is to calculate
2^2^2^2.... mod phi(7^7) = 2^2^2^2.... mod 2*3*7^6.
It's a bit harder, because "
2^2^2^2...." and modulo (
2*3*7^6) are not coprime. You can solve this using Chinese remainder theorem
http://en.wikipedia.org/wiki/Chinese_remainder_theorem.
You can divide modulo into
2 and
3*7^6, calculate
2^2^2^2.... mod 2 (it's 0) and
2^2^2^2.... mod 3*7^6, and then construct the result (because
2 and
3*7^6 are coprime, you can use Chinese remainder theorem).
But now we still have something to solve:
2^2^2^2.... mod 3*7^6. Looks very similar to previous problem (recursion

). I've created function which takes modulo (as powers of 2,3 and 7) and returns 2^2^2^2^2.... mod argument.
I hope you've understood something, writing math symbols in plaintext is quite hard and ugly
