Did you say 5 billion digits? That isn't a "large" number... That is a ridiculous number.
If it were a 1 followed by 5 billion zero's, it would be 2^(5 billion), which is close enough to infinity for me.
This sounds like one of those "get a guaranteed A in class if you solve this" problems. Well, guess what? Nobody every does.
That said, if my life depended on this problem, I would investigate using LISP. My only reason for saying that is I have a vague memory of reading about being able to generate crazy big numbers without sucking up memory with LISP. If I find where this memory is coming from I'll let you know. But don't count on it.
Good luck,
Paul