P301: Added Mathematica solution.
P301: Optimized solutions using math.
P301: Optimized all solutions with more math and dynamic programming.