This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
You are going to get to some pretty big numbers pretty fast. Further, you are going to have a fairly slow program if you do it by brute force. I'd suggest finding a math textbook and see if there is some easier way to compute these values. I didn't get that far in math, so I have no idea, but there is probably something out there.
research would be your best bet at this point.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors