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