MATHS FUN. (I also have Python fun here if that's more your thing)
Did you know that if you only want to work out the last x digits of the result of some kind of mathematical proceedure, you can calculate it modulo 10^x? Yes, you can!
For instance, the number (28433 * (2^7830457) + 1 ) is several thousand digits long, but if you only want the last 10, you can bung it into a program keeping it congruent to 10^10, and my wonderful 1-line Python program [Python is great in that it doesn't require any trickery whatsoever to work with absolutely huge numbers. I don't think it's possible to make them overflow. You can put in a 100 digit number and it doesn't bat an eyelid. It also has an interactive console thingy which makes it perfect for 1 line programs, unlike Java which wants class definitions and everything] works it out in about a second or so. If you got it to compute all digits, it'd take forever.
Further, you can speed up the exponentiation process (but writing the code to do so would have taken vastly longer than the time I'd save on the computation, so you know, I didn't) by repeated squaring. On a simple example, if you want to work out 2^11 mod 10, what you do is you observe that 2^11 = 2^1 * 2^2 * 2^8 (note you want to get the powers in the form of a binary string, regardless of what the number is which you're raising to those powers.) So, first you work out 2^1, then you square it up, giving you 2^2, then you repeat that until you've got all the numbers you need:
2^1 = 2 mod 10
Then, 2^2 = 4 mod 10
Then 4^2 = 6 mod 10
Then 6^2 = 6 mod 10
So then you put the 1st, 2nd and 4th of those together (the 3rd was 2^4 which isn't needed by itself but it was a stepping stone to 2^8), and you get 2*4*6 mod 10, giving 2*4 mod 10, giving 8 mod 10. So 2^11 is congruent to 8 mod 10 :)
That means 2^11 divided by 10 gives a remainder of 8. You can check that yourself.
I did then write some Python to do it, you know, just for fun.
I tested on this number, which I wanted calcuated mod 10^20 (last twenty digits): 2^701830457 (this is a huge number, I stuck in an extra two numbers than before, and would take a small rainforest to represent on paper)
Just for kicks, I compared the repeated squaring with asking Python to calculate it outright.
$ ./modexp.py 21253764960980303872 Repeated squaring done in 0.00078296661377s 21253764960980303872 The long way done in 8.73348116875s
def repeatedSquare(n, p, m):
powers = toBinary(p)
powersLen = len(powers)
product = 1
raised = n
for i in range(powersLen):
if powers[powersLen-i-1] == "1":
product = (product*raised)%m
raised = raised**2 % m
return product