Struggled through this puzzle and discovered in a hard way that the Math library in Java will sometimes produce a precision error when producing long integer results.
long n = (long)Math.pow(9, 17)
n value given by java is 16677181699666570
using a calculator to cross check, 9^17 is 16677181699666569
Math.pow deals with double. It loses precision when double is cast to long. I believe many other languages have a similar limitation, causing strange errors when solving extreme problems.