This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Just to expand a little on why that program works for a = (2^31) - 1. Now, since the largest possible positive int value is (2^31) - 1, you're right that you would get numeric overflow if you tried to calculate it in that order: the (2^31) will overflow before you have a chance to subtract the 1. However, if you unwind the calculation that is being done in line 12 of the program, what is actually being calculated is essentially (2^30) + (2^30 - 1). So the final step is an addition, and no overflow takes place.
[edit:] In looking back over your question, I realized that maybe you're confused about a different aspect of the problem. In the loop iteration when i = 31, it is true that the calculation for a[i+2] is going to be wrong due to overflow (as will have been a[i+1]). But that doesn't matter, because what is being printed in that iteration is a[i], which was calculated two iterations back and is correct.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com